Post by ssjal » Sun Dec 18, 2011 6:52 pm

In the Print Invoice template , how can we have the field displaying the total number of orders given by same client till date?

The same field is displayed in the Customer Orders Report under reports > customers > order > No. Orders(column)

thanks.

New member

Posts

Joined
Thu Sep 17, 2009 4:45 pm

Post by hydrowire » Mon Dec 19, 2011 5:48 pm

Hi ssjal,

You need to create your own query to call that total.

Open and edit admin/model/sale/order.php and add a function to calculate total order by a customer:

Code: Select all

public function getTotalOrdersByCustomerId($customer_id) {
	$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE customer_id = '" . (int)$customer_id. "' AND order_status_id != 0");

	return $query->row['total'];
}
Then call the function in your controller here in admin/controller/sale/order.php around line 2060:

Code: Select all

'order_total' => $this->model_sale_order->getTotalOrdersByCustomerId($order_info['customer_id']),
So now you can use the 'order_total' variable in your invoice, for example, in admin/view/template/sale/order_invoice.tpl after line 37:

Code: Select all

<tr>
    <td><b>Number of orders from this customer so far:</b></td>
    <td><?php echo $order['order_total']; ?></td>
</tr>
Hope this will get you started somehow.

Developing Quality OpenCart Extensions since 2011.
View my extensions


User avatar
Active Member

Posts

Joined
Wed Jan 26, 2011 5:41 pm


Post by ssjal » Mon Dec 26, 2011 7:58 pm

thanks hydrowire
your code worked perfectly.

New member

Posts

Joined
Thu Sep 17, 2009 4:45 pm

Post by yusufs » Sun May 14, 2023 2:36 am

Hello,
Is there any code suitable for opencart 3.0.3.2?

Newbie

Posts

Joined
Mon Jun 22, 2020 10:07 pm
Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 21 guests