Jump to content

Cart: Number Of Items Vs Number Of Products


praneth

Recommended Posts

Hello everyone,

 

Currently, my cart shows the number of items and not the number of products ordered.

 

For instance, if I add 10x iPod to the cart, it will show "10 products". I would like it to show "1 product" (as it is 10 occurrences of 1 product).

 

 

Would anyone know how to fix this (in v. 1.5.3)?

 

Thanks!

Edited by praneth (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

I make a replay of my own :rolleyes:

 

To display number of items in PS 1.4.8

open file /classes/cart.php

 

find code

 

public static function getNbProducts($id)
{
 // Must be strictly compared to NULL, or else an empty cart will bypass the cache and add dozens of queries
 if (isset(self::$_nbProducts[$id]) && self::$_nbProducts[$id] !== NULL)
  return self::$_nbProducts[$id];
 self::$_nbProducts[$id] = (int)(Db::getInstance()->getValue('
  SELECT SUM(`quantity`)
  FROM `'._DB_PREFIX_.'cart_product`
  WHERE `id_cart` = '.(int)($id)));
 return self::$_nbProducts[$id];
}

and replace with code

public static function getNbProducts($id)
{
 // Must be strictly compared to NULL, or else an empty cart will bypass the cache and add dozens of queries
 if (isset(self::$_nbProducts[$id]) && self::$_nbProducts[$id] !== NULL)
  return self::$_nbProducts[$id];
 self::$_nbProducts[$id] = (int)(Db::getInstance()->getValue('
  SELECT COUNT(*)
  FROM `'._DB_PREFIX_.'cart_product`
  WHERE `id_cart` = '.(int)($id)));
 return self::$_nbProducts[$id];
}

 

Best wishes

Link to comment
Share on other sites

  • 9 months later...

Hello,

this solution works only when you refresh page. When you click add to cart (let's say 10 items), it shows 10 products, but when refresh page, it shows 1 product. 

So does anyone know how to fix this problem ?

 

I'm using presta 1.5.6.2.

 

Thank you.

Link to comment
Share on other sites

  • 2 years later...

I replace this subject because I have the same problem and can't find the solution

 

I test the change in query on 1.6.1.5 and  it works but only after refreshing page

When you click add to cart (let's say 10 items), it shows 10 products, but when refresh page, it shows 1 product. 

 

 

Anyone have find how to fix it since last year ? 

 

Thanks in advance

Link to comment
Share on other sites

  • 7 months later...

I'm using 1.6.1.4. And a screenshot...hm, I don't know if it's helpful^^

 

I mean there is not much to see than two different numbers.

When I put 12 pieces of a product to the cart, it shows 12

When I reload the page or go to a different one, the cart shows 1 - which would be correct/what I'd like to have.

Link to comment
Share on other sites

  • 1 year later...

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