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:
<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);
$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 += $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
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
Disregard, I figured it out.
Sean