Jump to content

[SOLVED] Show total amount of sold products in store


tobbecokta

Recommended Posts

you can do it with custom development only,

module, or modification of front controller where you can include code to get sum of all orders

    public static function sales(){
        $sql = 'SELECT COUNT(o.`id_order`) as orderCount, SUM(o.`total_paid_real` / o.conversion_rate) as orderSum
				FROM `'._DB_PREFIX_.'orders` o
				WHERE o.valid = 1';
		$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        return $result1['orderSum'];
    }

then use code:

{FrontController::sales()}
Link to comment
Share on other sites

Vekia you are really fast to reply, thank you for your help!

 

However, it turns out that i wasn't so clear when i wrote what i was looking for..

 

I would like to display the total number of products sold, not the amount. Sorry, my misstake. Do you think you can help me modify your code (that works great by the way) so that it instead displays the total units sold?

Link to comment
Share on other sites

ok i modified it:

    public static function sales(){
        	$sql = 'SELECT SUM(od.product_quantity) as products
				FROM `'._DB_PREFIX_.'orders` o
				LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON od.`id_order` = o.`id_order`
				WHERE o.valid = 1 '.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
				$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        return $result1['products'];
    }
Link to comment
Share on other sites

 

ok i modified it:

    public static function sales(){
        	$sql = 'SELECT SUM(od.product_quantity) as products
				FROM `'._DB_PREFIX_.'orders` o
				LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON od.`id_order` = o.`id_order`
				WHERE o.valid = 1 '.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o');
				$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        return $result1['products'];
    }

 

 

Works like a charm, thanks for your help!

Link to comment
Share on other sites

  • 11 months later...

Hi and thank you for your help.

 

I have a little question. I have copy the code in my php module.

I want to use the orderSum in my Tpl (hooked).

 

You mentionned the {FrontController::sales()} but when I write that between a <div> on my tpl, it doesnt work and my sheet is white.

 

How to use this Sumorder in my tpl ?

 

Thank you for your 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...