Post by feedermania » Sun Feb 23, 2020 1:45 am

Im beginner. What is the right syntax? I want to get the discount.
Table: customer
Column: discount

Code: Select all

  public function getCustomerDiscount($customer_id,$customer_group_id) {
    $xml     = '';
    $query   = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE discount = '".(int)$discount."'");
    $customer = $query->row;
    foreach($export_items as $item){
      if($item == 'discount'){$xml .= '<DISCOUNT>'.htmlspecialchars($customer['discount']).'</DISCOUNT>'."\n";}
   }
   return $xml;
  }

New member

Posts

Joined
Mon Jul 30, 2018 2:48 am

Post by sw!tch » Sun Feb 23, 2020 4:42 am

Code: Select all

public function getCustomerDiscount($customer_id, $customer_group_id){
        $query = $this->db->query("SELECT discount FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "' and `customer_group_id` = '" . (int)$customer_group_id . "'");

        $xml = '';
        
        if (isset($query->row['discount'])) {
            $xml .= '<DISCOUNT>' . htmlspecialchars($query->row['discount']) . '</DISCOUNT>' . "\n";
        }

        return $xml;
    }

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by letxobnav » Sun Feb 23, 2020 11:31 am

Code: Select all

public function getCustomerDiscount($customer_id, $customer_group_id){
        $query = $this->db->query("SELECT discount FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "' and `customer_group_id` = '" . (int)$customer_group_id . "'");

        $xml = '';
        
        if (isset($query->row['discount'])) {
            $xml .= '<DISCOUNT>' . htmlspecialchars($query->row['discount']) . '</DISCOUNT>' . "\n";
        }

        return $xml;
    }

This is a dumb function:
1) the customer table only has one customer group id per customer id so the where clause on that is useless if you have the customer_id
2) you do not return xml from a function called "getCustomerDiscount", you return the discount.

Code: Select all

public function getCustomerDiscount($customer_id){
        $query = $this->db->query("SELECT discount FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
        if (isset($query->row['discount'])) {
            return $query->row['discount'];
        }
        return false;
    }

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by sw!tch » Sun Feb 23, 2020 11:56 am

Well the proper way would be to place this in your model, return discount and the logic handled from the controller. Thats the whole point to MVC, not sure what OP is using it for.

Code: Select all

public function getCustomerDiscount($customer_id){
        $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");

        return $query->row['discount'];
    }
In short there is really no need for this function to begin with its repetitive.

Code: Select all

// Admin
$this->load->model('customer/customer');
$customer =  $this->model_customer_customer->getCustomer($customer_id);
echo $customer['discount'];

// Catalog
$this->load->model('account/customer');
$customer =  $this->model_account_customer->getCustomer($customer_id);
echo $customer['discount'];

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by letxobnav » Sun Feb 23, 2020 1:33 pm

not sure what OP is using it for
The OP doesn't know what he is doing.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by kestas » Sun Feb 23, 2020 5:16 pm

feedermania wrote:
Sun Feb 23, 2020 1:45 am
Im beginner. What is the right syntax? I want to get the discount.
Table: customer
Column: discount

Code: Select all

  public function getCustomerDiscount($customer_id,$customer_group_id) {
    $xml     = '';
    $query   = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE discount = '".(int)$discount."'");
    $customer = $query->row;
    foreach($export_items as $item){
      if($item == 'discount'){$xml .= '<DISCOUNT>'.htmlspecialchars($customer['discount']).'</DISCOUNT>'."\n";}
   }
   return $xml;
  }
If I correctly understand you use module for export orders XML and another one extension for discount. (I saw the same question in stackoverflow). So if you need some suggestion, please upload your order XML module and tables structure where your discount is placed (in your case seems in "customer" table). Maybe someone will help you.
Or you can place request on commercial forum. viewforum.php?f=88

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am
Who is online

Users browsing this forum: No registered users and 9 guests