Page 1 of 1

How to get total quantity of products in cart?

Posted: Fri Jun 04, 2010 8:39 pm
by VHalek
Hello,
don't you know how to get number "total quantity of products" in the cart in the right column? Right now, I've got just total price, but I'd like to have something like:
You have 3 items, total price is 100GBP
Thank you very much.

Re: How to get total quantity of products in cart?

Posted: Sat Jun 05, 2010 6:17 am
by JAY6390
Are you wanting the total stock or the quantity of different products?
Lets say you have
3 x LCD Screen
2 x iPod

Do you want the number 2 since there are 2 different products, or 5 since there are a total of 5 products in the cart

Re: How to get total quantity of products in cart?

Posted: Sat Jun 05, 2010 6:28 am
by VHalek
If we have this situation (with your products), I'd like to have this written in the cart:
You have 5 items, total price is xxx.

Re: How to get total quantity of products in cart?

Posted: Sat Jun 05, 2010 6:48 am
by JAY6390
You can put this in your template wherever you want it

Code: Select all

<?php echo $this->cart->countProducts(); ?>
@OC developers - The cart function to this can be simplified
Current code:

Code: Select all

      public function countProducts() {
        $total = 0;
        
        foreach ($this->session->data['cart'] as $value) {
            $total += $value;
        }
        
        return $total;
      } 
Simplified:

Code: Select all

public function countProducts() {
    return array_sum($this->session->data['cart']);
} 

Re: How to get total quantity of products in cart?

Posted: Sat Jun 05, 2010 7:37 am
by VHalek
Thank you very much, that's exactly what I was looking for.

Again - thank you.

Re: How to get total quantity of products in cart?

Posted: Sat Jun 05, 2010 8:29 am
by JAY6390
No problem :)

Re: How to get total quantity of products in cart?

Posted: Tue Apr 01, 2014 10:03 am
by orientcart
I can not find any extension for this, anyone can help me out ???

Re: How to get total quantity of products in cart?

Posted: Thu Feb 10, 2022 7:47 pm
by OSWorX
pauliakas wrote:
Wed Feb 09, 2022 9:45 pm
Maybe someone has working code for 3.0.2.0 version?
Should be the same code.