little tiny correction to uc_cart

Posts: 17
Joined: 08/16/2007
Internationalizationizer

Thers's just a little bug in some case when cart is empty, it says 1 item.
uc_cart.module / line 374

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

perhaps better something like
$item_text = format_plural($item_count, t('0 Item'), '@count Items');

regards
thx Übercart !
Mog

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

That wouldn't be where the bug is. For whatever reason, $item_count is 1 when it should be 0. format_plural() takes a number, a singular string, and a plural string as arguments. If the number is 1, it returns the translated singular string, else it returns the translated plural string.

The real question is why the count is wrong.

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Aye, I don't see why the count would be wrong here.

Two things... first, are you using English language or a translated language? Second, can you try emptying your uc_cart_items table and checking again? In the past, rogue items could have been left in the cart but not listed in the block.

Posts: 17
Joined: 08/16/2007
Internationalizationizer

Hi,

First : sorry, i haven't read form_plural() manual before post. (and i always say to other to read the manaul before questionning ... shame on me)

i found the problem : plural_form(), in case of $count = 0 return singular string (here "1 Item") changing @count to passed $count.
so it would be better "@count Item" for singular form, and it returns "0 Item", cause 1 and 0 are both singular Eye-wink.

Here is an other suggestion, perhaps it would be better to not show this line (count and total) if cart is empty or set an option to display it or not...

Regards
Mog

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Hmm... what language are you using on the site, Mog?

Also, for now you can simply hide the cart block when it's empty in the block settings, but I wouldn't be opposed to making this line not display for empty carts.

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

Well, color me surprised. I even took French in high school, but I don't remember being told that zero is singular. It shouldn't be too big a deal to fix all the format_plural()'s in the code.