Hi Everyone,
I am helping a client out by installing some tracking on their order successful process.
We have managed to get the tracking installed and access order_number & total_amount via the success.php & success.tpl
We are using version 1.5.4
What the client would now like to do is manipulate this code based on the number of times the customer has ordered. Obviously this would only apply to customers logged in (not guest orders).
What I would like to know is if we can get the total number of past orders for a customer on the success.php process.
This will allow me to use some php to send different values based on this integer.
Thanks for all your help in advanced.
I am helping a client out by installing some tracking on their order successful process.
We have managed to get the tracking installed and access order_number & total_amount via the success.php & success.tpl
We are using version 1.5.4
What the client would now like to do is manipulate this code based on the number of times the customer has ordered. Obviously this would only apply to customers logged in (not guest orders).
What I would like to know is if we can get the total number of past orders for a customer on the success.php process.
This will allow me to use some php to send different values based on this integer.
Thanks for all your help in advanced.
In catalog/controller/checkout/success.php file,
find:
add right below:
Then, you could use the $total_orders variable into your custom success.tpl template file.
find:
Code: Select all
if (isset($this->session->data['order_id'])) {
Code: Select all
if ($this->customer->isLogged()) {
$total_orders = $this->db->query("SELECT COUNT(`order_id`) AS `total` FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$this->session->data['order_id'] . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
$this->data['total_orders'] = (int)$total_orders->row['total'];
}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Late reply, but since we are also messing with this on the admin side, here is a thought.
This may work different catalog side, but the post above seems to get orders without considering order status 0 which is "missing orders". So if a customer doesnt complete an order twice, then checks out successfully, the count may show 3 orders when you only want it to show the 1 successful (not the other 2 missing orders of status 0).
If you need order counts on admin side, here is a snippet. In admin/model/sale/order.php you can make a new function to get total orders by customer id:
Now anything that uses the order model is able to quickly pull a count of a customers orders with status greater than 0. To use it, it would look like this (replace customer_id variable with whatever makes customer id in your controller/view):
Keep in mind, there is a customer id of 0 that is sometimes used if customer is deleted. So its a good idea to check against that too, otherwise it may show inaccurate counts for deleted customers
This may work different catalog side, but the post above seems to get orders without considering order status 0 which is "missing orders". So if a customer doesnt complete an order twice, then checks out successfully, the count may show 3 orders when you only want it to show the 1 successful (not the other 2 missing orders of status 0).
If you need order counts on admin side, here is a snippet. In admin/model/sale/order.php you can make a new function to get total orders by customer id:
Code: Select all
public function getTotalOrdersByCustomerId($customer_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > 0 AND customer_id = '" . (int)$customer_id . "'");
return $query->row['total'];
}
Now anything that uses the order model is able to quickly pull a count of a customers orders with status greater than 0. To use it, it would look like this (replace customer_id variable with whatever makes customer id in your controller/view):
Code: Select all
$this->model_sale_order->getTotalOrdersByCustomerId($customer_id)
https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.
Hi,straightlight wrote: ↑Thu Jun 19, 2014 7:19 pmIn catalog/controller/checkout/success.php file,
find:
add right below:Code: Select all
if (isset($this->session->data['order_id'])) {
Then, you could use the $total_orders variable into your custom success.tpl template file.Code: Select all
if ($this->customer->isLogged()) { $total_orders = $this->db->query("SELECT COUNT(`order_id`) AS `total` FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$this->session->data['order_id'] . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'"); $this->data['total_orders'] = (int)$total_orders->row['total']; }
I'm trying to get the total number of the orders to display on user account page but its not working.
OC 3.x
its shows error ParseError: syntax error, unexpected 'public' (T_PUBLIC)
code that i place in controller/account/account.php
if ($this->customer->isLogged()) {
$total_orders = $this->db->query("SELECT COUNT(`order_id`) AS `total` FROM `" . DB_PREFIX . "order` WHERE `order_id` = '" . (int)$this->session->data['order_id'] . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
$data['total_orders'] = (int)$total_orders->row['total'];
}
and
{{ total_orders in }} theme account.twig file.
Replace:OC 3.x
its shows error ParseError: syntax error, unexpected 'public' (T_PUBLIC)
Code: Select all
$this->data
Code: Select all
$data
Code: Select all
{{ total_orders in }}
Code: Select all
{{ total_orders }}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Who is online
Users browsing this forum: No registered users and 118 guests