function total_qty() added to Cart.php #289

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
7 participants

total_items() returns total items in the cart. For example we have 2 items in the cart Apple and Orange, and there 2(qty) Apples and 1(qty) Orange. total_items() returns 2, because there are 2 items. But there should be a method which should return 2(qty). I have added this method to Cart.php

function total_qty()
{
    $total=0;

    foreach($this->contents() as $item)
    {   
        $total+=$item['qty'];
    }

    return $total;
}
Contributor

chrisberthe commented Aug 24, 2011

Thank you - too bad the Cart class is getting killed though.

why is the cart class getting killed?

Contributor

chrisberthe commented Aug 24, 2011

Same question. Its sad :( , I have many projects using it, works good for me, though I have extended it a litlle.

Contributor

marcoscoelho commented Aug 24, 2011

Contributor

gaker commented Aug 25, 2011

I'm not nuts about the function name. Can you rename it to total_quantity(), add it to the documentation, and change log please? Then we can merge 'er in!

Contributor

marcoscoelho commented Aug 25, 2011

@gaker this was fixed not? see change log..

@gaker I have also found in the change log 2.0.3 "Fixed a bug where the method $this->cart->total_items() from Cart Library now returns the sum of the quantity of all items in the cart instead of your total count." so may be its fixed as bug, I was not aware of it. But knowing total number of items irrespective of their quantity was also an important one.

Contributor

marcoscoelho commented Aug 25, 2011

@usmanhalalit
[…] knowing total number of items irrespective of their quantity was also an important one.

<?php

$total_items = $this->cart->total_items()
$num_items = count($this->cart->contents()); // maybe this could be wrapped in a new method

@marcoscoelho hmmm, good one.

Surely even if the Cart class is being killed and added as a spark, that there will still be the opportunity to make and accept pull requests for additions to the class?

I think in that case it will be a different project here on github and we can fork-pull.

narfbg closed this Oct 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment