MNT Posted September 1, 2011 Share Posted September 1, 2011 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 More sharing options...
phrasespot Posted September 4, 2011 Share Posted September 4, 2011 Looks correct... Dump just before smarty assignment to see if you are getting what you expect from DB queries. Also have a look at the ::getValue method (instead of ::executeS) to use with Select statements that just retrieve a single value. Link to comment Share on other sites More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 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 More sharing options...
phrasespot Posted September 5, 2011 Share Posted September 5, 2011 What is the version of prestashop you have installed? Link to comment Share on other sites More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 1.417 Link to comment Share on other sites More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 Sorry: prestashop 1.4.0.17 Link to comment Share on other sites More sharing options...
phrasespot Posted September 5, 2011 Share Posted September 5, 2011 OK, create a class FrontController extends FrontColtrollerCore {} override its displayFooter() method and put your code in there, then call the parent::displayFoorter(). Place the class in /override/classes/ directory. Let me know if you need more detailed help. Link to comment Share on other sites More sharing options...
phrasespot Posted September 5, 2011 Share Posted September 5, 2011 I cannot edit the previous post, should say FrontControllerCore and displayFooter() Link to comment Share on other sites More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 AH yes they just changed it Link to comment Share on other sites More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 _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 More sharing options...
MNT Posted September 5, 2011 Author Share Posted September 5, 2011 If I can show the total orders anywhere in the website, even in the cart or footer will be fine. thanks for help Link to comment Share on other sites More sharing options...
phrasespot Posted September 5, 2011 Share Posted September 5, 2011 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 1 Link to comment Share on other sites More sharing options...
MNT Posted September 6, 2011 Author Share Posted September 6, 2011 Works great, thanks for that. Can you tell me how I can show it in the order-address.tpl? (because I want to disable the next botton if the a client order more that X amount current month). Thanks Link to comment Share on other sites More sharing options...
MNT Posted September 6, 2011 Author Share Posted September 6, 2011 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 More sharing options...
MNT Posted September 6, 2011 Author Share Posted September 6, 2011 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 More sharing options...
MNT Posted September 6, 2011 Author Share Posted September 6, 2011 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 More sharing options...
Prestashop learner Posted August 14, 2014 Share Posted August 14, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now