Cart class - total_items() not displaying actual total - bug? |
[eluser]nottRobin[/eluser]
Imagine I have a shopping cart with the following items: Code: // rows removed for readability Now to my thinking the "total number of items" in this cart should be Code: 4+5=9 However, this is not what the "total_items()" (see the Cart documentation) method outputs: Code: die((string)$this->cart->total_items()); // outputs "2" - not "9" Can anyone enlighten me as to why this is? And possibly tell me if the cart class does in fact support outputting "total items" in the way that I want? Cheers, Robin.
[eluser]nottRobin[/eluser]
The reason why I think it would be more helpful if the "total_items" method output what I'm going to call "total discrete items" rather than "total item types" is because, if you want the latter, you can get it easily enough using the following code: Code: die((string)count($this->cart->contents())); // Outputs "2" So it would far more helpful if the method "total_items()" had the more complex "total discrete items" functionality instead.
[eluser]nottRobin[/eluser]
If anyone confirms they think this is a bug, I will submit it to bug tracker. In the meantime, fixing it isn't that hard. Edit - This fix is deprecated. Please see my next post below. Just add the following method to the end of /system/libraries/Cart.php (before the final '}'): Code: /** Now, for the cart mentioned above: Code: die( Please let me know if anyone else finds this useful.
[eluser]coffeeandcode[/eluser]
[quote author="nottRobin" date="1280255910"]Just add the following method to the end of /system/libraries/Cart.php (before the final '}'[/quote] It's much better to extend the library in /system/application/libraries/MY_Cart.php. Anything you add there will be added to the system's class. Creating Libraries - see the section entitled "Extending Native Libraries".
[eluser]nottRobin[/eluser]
Thanks coffeeandcode. I've now removed my edits to system/libraries/Cart.php, and created a new file in /system/application/libraries/My_Cart.php: Code: <?php
[eluser]stikoo[/eluser]
Thanks nottRobin, This is exactly what I was after, I too was about to make the same mistake and shove a piece of code into the Core Library lol, So thanks for the above info! |
Welcome Guest, Not a member yet? Register Sign In |