Jump to content

[SOLVED] how to show the total number of...


Recommended Posts

You'll need to 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}

Link to comment
Share on other sites

Tip:

if you need to show the exact number of how much items sold you need to use this code in header.php or footer.php

$totalOrders = Db::getInstance()->executeS('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders`');
$totalOrderProducts = Db::getInstance()->executeS('SELECT SUM(product_quantity) as total_order_products FROM `'._DB_PREFIX_.'order_detail`');
$smarty->assign(array('totalOrders' => $totalOrders[0]['total_orders'], 'totalOrderProducts' => $totalOrderProducts[0]['total_order_products']));



the difference here between

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



and

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



is that the first line of code showing how many records in the table ._DB_PREFIX_.'order_detail by using SELECT COUNT(*). where the second code calculate the total number of quantities sold by using SELECT SUM(product_quantity).

HTHs someone.

Again, thanks for rocky for his help... without his help I couldn't get that done.

Link to comment
Share on other sites

  • 1 year later...

Hello, I find very interesting subject, and I wonder if I can help with any questions I have about the code provided, I could show the total number of orders "but only for the current month" and I can solve it, thank you very much for your help, greetings.

For example:

Number of orders: {$totalOrders} for the current month ?


Edit: The code displays the total of orders placed, but also includes canceled orders, how can you do to show only orders validated ?



One idea:

That with the sentence they between fodder that could be solved, but not like making it without I have to introduce the dates manually, want that become automatic for the present month

BETWEEN value1 AND value2

Sorry for my bad english !

Link to comment
Share on other sites

My Solution:

$totalOrders = Db::getInstance()->executeS('SELECT COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW())');
$totalOrderProducts = Db::getInstance()->executeS('SELECT COUNT(*) as total_order_products FROM `'._DB_PREFIX_.'order_detail` WHERE MONTH(`date_add`) = MONTH(NOW()) AND YEAR(`date_add`) = YEAR(NOW())');
$smarty->assign(array('totalOrders' => $totalOrders[0]['total_orders'], 'totalOrderProducts' => $totalOrderProducts[0]['total_order_products']));

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...