Small issue with uc_cart

Posts: 56
Joined: 01/23/2008
Bug Finder

Hi

I've just updated to beta 6, and I've seen a small issue with the cart behavior: It always says that I have 1 Item in the cart even when it is empty.

I've found the gap in uc_cart.module on line 380

$item_text = format_plural($item_count, '1 Item', '@count Items');

This always returns 1 Item when $item_count is 0.

I've modified that line for including the 0 option, if somebody has a better suggestion I'd like to see it!!!

if ($item_count == 0) {
    $item_text = '0 '.t('Items');
  }
  else {
  $item_text = format_plural($item_count, '1 Item', '@count Items');
  }

_Pedro

Posts: 1998
Joined: 08/07/2007
AdministratoreLiTe!

This has actually been taken care of, though I haven't yet said so in this thread. What did was change '1 Item' to '@count Item', because some languages consider 0 to be singular. This allows the translators to figure out what we're trying to communicate in this spot.

Posts: 56
Joined: 01/23/2008
Bug Finder

Great thanks Lyle,

but I have to clarify that is not a singular-plural issue, is that when the cart is empty, it shows "1 Item" and not "0 Items as it should

PD: In Spanish 0 is plural too Sticking out tongue

Posts: 1998
Joined: 08/07/2007
AdministratoreLiTe!

Maybe a product kit got corrupted and left a product in the cart when it was deleted. I've seen funny things happen sometimes. Check the uc_cart_products table to see if there are rows for your user id that don't belong. If there is, delete it, and your count should be accurate again.

On a side note, I noticed that the es.po for CCK has 0 being singular. Someone should tell them that's not right.

Posts: 56
Joined: 01/23/2008
Bug Finder

No, I've checked the $item_count variable before the call to format_plural and it was 0 (and the table is empty too, of course).
Is this happening only to me?

I fixed it checking if $item_count is 0 before of converting it to plural...

Posts: 1998
Joined: 08/07/2007
AdministratoreLiTe!

Is this happening in English or Spanish? I checked the es.po file available at rak's translation server, and it has a correct plurals formula. But if whatever po file you're using doesn't have the right formula to determine plural-ness, this kind of thing happens.

The correct line near the top of the .po file is
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
This is what you should find for most languages.

However, if a translator misconfigured something, or just copied the po header from French, you'd see something like
"Plural-Forms:  nplurals=2; plural=(n > 1);\n"

Posts: 56
Joined: 01/23/2008
Bug Finder

I was happening in spanish and english, but now it is solved, I've restored the original code and it works Puzzled (maybe because I've updated the .po file from the translation server?)

Thanks Lyle!