I am using prestashop 1.6 and I create a function into classes/Cart.php, This one count items in shopping-cart but that items are products without discount or reduction price.
/* @return int Cart Item not on_sale
*/
public function getTotalItems()
{
$total_items = 0;
$total_items = (int)Db::getInstance()->getValue('
SELECT SUM(`quantity`)
FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_cart` = '.(int)$id
'AND p.`active` <> 1 AND p.on_sale <> 1'
);
return $total_items;
}
And this is shopping-cart.tpl call
{$cart->getTotalItems()|escape:'htmlall':'UTF-8'|number_format:0}
But the return is 0, of course into my basket i have products with and without discount.
What is wrong?
(int)$id
will always result in 0 as it is undefined. You need to use $this->id
to get the cart id.
$total_items = (int)Db::getInstance()->getValue('
SELECT SUM(`quantity`)
FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_cart` = '.(int)$this->id.
' AND p.`active` <> 1 AND p.on_sale <> 1'
);