Updating a int in c...
 
Notifications
Clear all

Updating a int in column in database

3 Posts
1 Users
0 Likes
2,713 Views
(@slthompson)
Posts: 8
Active Member
Topic starter
 

I'm using opencart and a rewards point addon module so when a user buys coins on my website for real money the rewards points are added to their coins column in the user table. I'm having a hard time figuring out how to make this happen.

The table name has a prefix, table name is 'customer', each customer has an id 'customer_id' and the column that needs to be updated (int added) with the reward points is 'coins'.

This is the script that does this:

<modification>
 <id>Auto Reward Points</id>
 <version>OC 1.5</version>
 <vqmver>2.0.0</vqmver>
 <author>Equotix</author>
 <!-- ADMIN -->
 <file name="admin/model/sale/order.php">
  <operation>
   <search position="after"><![CDATA[
    addOrderHistory(
   ]]></search>
   <add><![CDATA[
    // Auto Reward Points
    $this->load->model('sale/customer');
    
    $reward_total = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($order_id);
    if (!$reward_total && $data['order_status_id'] == $this->config->get('config_complete_status_id')) {
     $this->language->load('sale/order');
     
     $order_info = $this->getOrder($order_id);
    
     if ($order_info['customer_id'] && $this->config->get(base64_decode('YXV0b19yZXdhcmRfcG9pbnRzX2xpY2Vuc2VfbGljZW5zZV9rZXk='))) {
      $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$order_info['customer_id'] . "', order_id = '" . (int)$order_id . "', points = '" . (int)$order_info['reward'] . "', description = '" . $this->db->escape($this->language->get('text_order_id') . ' #' . $order_id) . "', date_added = NOW()");
     }
    }
    // End Auto Reward Points
   ]]></add>
  </operation>
 </file>
 <!-- CATALOG -->
 <file name="catalog/model/checkout/order.php">
  <operation>
   <search position="after"><![CDATA[
    function confirm(
   ]]></search>
   <add><![CDATA[
    // Auto Reward Points
    $reward = 0;
    $reward_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
    foreach ($reward_query->rows as $product) {
     $reward += $product['reward'];
    }
    
    $reward_total = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "' AND points > 0");
    
    if (!$reward_total->row['total'] && $order_status_id == $this->config->get('config_complete_status_id')) {
     $this->language->load('account/order');
    
     $order_info = $this->getOrder($order_id);
   
     if ($order_info['customer_id'] && $this->config->get('auto_reward_points_license_license_key')) {
      $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$order_info['customer_id'] . "', order_id = '" . (int)$order_id . "', points = '" . (int)$reward . "', description = '" . $this->db->escape($this->language->get('text_order_id') . ' #' . $order_id) . "', date_added = NOW()");
     }
    }
    // End Auto Reward Points
   ]]></add>
  </operation>
 </file>
</modification>
 
Script also added as attachment.

Sean

 
Posted : 06/07/2019 3:57 pm
(@slthompson)
Posts: 8
Active Member
Topic starter
 

That above script right now get order info and adds it to the table 'customer_reward'. I need to have it also find the use the order's customer id, find that id in the table 'customer' and add the 'rewards points' to the coins column for that user also. 

Note: you can see the script indicates a prefix associated with finding tables.

Sean

 
Posted : 06/07/2019 4:03 pm
(@slthompson)
Posts: 8
Active Member
Topic starter
 

Disregard, I figured it out.

Sean

 
Posted : 07/07/2019 11:43 pm
Share: