Jump to content

Show the orders total in the header,cart or footer for current month


MNT

Recommended Posts

Hello,

I want to show the total order for the current month for a current customer.

 

I tried the following code but it doesn't work:

 

add code like this to header.php or footer.php, depending on where you want the information displayed, before the $smarty->display:

 

$totalOrders = Db::getInstance()->executeS('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders`');

$totalOrderProducts = Db::getInstance()->executeS('SELECT COUNT(*) as total_order_products FROM `'._DB_PREFIX_.'order_detail`');

$smarty->assign(array('totalOrders' => $totalOrders[0]['total_orders'], 'totalOrderProducts' => $totalOrderProducts[0]['total_order_products']));

 

Then you can use the following in header.tpl or footer.tpl:

 

Number of orders: {$totalOrders}

Number of order products: {$totalOrderProducts}

 

Can you help please

Link to comment
Share on other sites

Thanks for replay.

I did all that, and still getting error message:

 

Number of orders:

Notice: Undefined variable: totalOrders inC:\wamp\www\prestashop\tools\smarty\sysplugins\smarty_internal_data.php on line 291

Number of order products:

Notice: Undefined variable: totalOrderProducts inC:\wamp\www\prestashop\tools\smarty\sysplugins\smarty_internal_data.php on line 291

 

I added in the footer.php:

 

$totalOrders = Db::getInstance()->executeS('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders`');

$totalOrderProducts = Db::getInstance()->executeS('SELECT COUNT(*) as total_order_products FROM `'._DB_PREFIX_.'order_detail`');

$smarty->assign(array('totalOrders' => $totalOrders[0]['total_orders'], 'totalOrderProducts' => $totalOrderProducts[0]['total_order_products']));

 

also I added in footer.tpl:

Number of orders: {$totalOrders}

Number of order products: {$totalOrderProducts}

 

also I tried ::getValue method (instead of ::executeS)

 

Can you help please?

Thanks in advance.

Link to comment
Share on other sites

_FrontControllerCore.php saved in /override/classes/

 

 

<?php

class FrontController extends FrontColtrollerCore

{

public function displayFoorter()

{

$totalOrders = Db::getInstance()->executeS('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders`');

$totalOrderProducts = Db::getInstance()->executeS('SELECT COUNT(*) as total_order_products FROM `'._DB_PREFIX_.'order_detail`');

$smarty->assign(array('totalOrders' => $totalOrders[0]['total_orders'], 'totalOrderProducts' => $totalOrderProducts[0]['total_order_products']));

}

}

?>

Link to comment
Share on other sites

Drop the attached file to /override/classes/ directory. Then find /themes/your theme/footer.tpl and add the following:

 

<div>Total orders: {$totalOrders}</div>
<div>Total products ordered: {$totalOrderProducts}</div>

just below:

 

<div id="footer">{$HOOK_FOOTER}</div>

I used the SQL statements from your original post, adjust as necessary (you'll need to if you want monthly totals only), also you can modify what goes into footer.tpl as you desire.

FrontController.php

  • Like 1
Link to comment
Share on other sites

It works, just need to get the current customer ID: id_customer, also how to show it in order-address.tpl?

 

FrontController.php

 

 

<?php

class FrontController extends FrontControllerCore {

public function displayFooter() {

$totalOrders = Db::getInstance()->getValue('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW()) AND id_customer="'.$id_customer.'"' );

$totalOrderProducts = Db::getInstance()->getValue('

SELECT SUM(total_paid)

FROM `' . _DB_PREFIX_ . 'orders` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW()) AND id_customer="'.$id_customer.'"' );

 

self::$smarty->assign(array(

'totalOrders' => $totalOrders,

'totalOrderProducts' => $totalOrderProducts));

parent::displayFooter();

}

}

?>

Link to comment
Share on other sites

Now working with current Customer:

 

 

<?php

class FrontController extends FrontControllerCore {

 

public function displayFooter() {

global $cookie;

$id_customer = $cookie->id_customer;

 

$totalOrders = Db::getInstance()->getValue('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW()) AND id_customer="'.$id_customer.'"' );

$totalOrderProducts = Db::getInstance()->getValue('

SELECT SUM(total_paid)

FROM `' . _DB_PREFIX_ . 'orders` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW()) AND id_customer="'.$id_customer.'"' );

 

self::$smarty->assign(array(

'totalOrders' => $totalOrders,

'totalOrderProducts' => $totalOrderProducts));

parent::displayFooter();

}

}

?>

------------------------------------------------------

I need to show this in the order-address.tpl? how can I do it?

Thanks for replay

Link to comment
Share on other sites

It works fine in blockcart.tpl or footer.tpl but I got error when I insert

 

 

Number of orders: {$totalOrders}

Number of order products: {$totalOrderProducts}

 

 

into order-address.tpl

 

 

Notice: Undefined variable: totalOrders in C:\wamp\www\prestashop\tools\smarty\sysplugins\smarty_internal_data.php on line 291

Notice: Undefined variable: totalOrderProducts in C:\wamp\www\prestashop\tools\smarty\sysplugins\smarty_internal_data.php on line 291

 

Can somebody help please?

Link to comment
Share on other sites

  • 2 years later...

Drop the attached file to /override/classes/ directory. Then find /themes/your theme/footer.tpl and add the following:

 

<div>Total orders: {$totalOrders}</div>
<div>Total products ordered: {$totalOrderProducts}</div>
just below:

 

<div id="footer">{$HOOK_FOOTER}</div>
I used the SQL statements from your original post, adjust as necessary (you'll need to if you want monthly totals only), also you can modify what goes into footer.tpl as you desire.

 

Its not working can you please help......

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...