Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total Number of Items #11

Closed
matalina opened this issue Apr 16, 2015 · 5 comments
Closed

Total Number of Items #11

matalina opened this issue Apr 16, 2015 · 5 comments

Comments

@matalina
Copy link

This is probably a function you want to add. Most carts these days display the total number of items in the cart. I see no function for this. Not hard for me to write, but thought I'd mention it.

@giovannefc
Copy link

Use:
Cart::getContent()->count();

Cart is a instance of the CartCollection.. You can use all functions of Collect library of laravel.

@matalina
Copy link
Author

thanks! didn't realize it was a collection.

On Thu, Apr 16, 2015 at 2:31 PM Gino [email protected] wrote:

Use:
Cart::getContent()->count();

Cart is a instance of the CartCollection.. You can use all functions of
Collect library of laravel.


Reply to this email directly or view it on GitHub
#11 (comment)
.

@lostcause
Copy link

Sorry for re-opening a closed issue, but I have a question about this subject. I need the total number of items, but not the Collections' items, but rather the total 'quantities' for all items in the cart. For example, I have Item1 x 2 and Item 2 x 5. The count should be 7, not 2.

@darryldecode
Copy link
Owner

I guess your issue is the same with this pull request: #13

Didn't merged it yet as I was waiting for another suggestion of a good method name for this as this a bit confusing with the existing Cart::getContent()->count().

for the meantime, you can just do like this as workaround.

$count = 0;

$items = Cart::getContent();

foreach ($items as $item) {
    $count += $item->quantity;
 }

@pvdptje
Copy link
Contributor

pvdptje commented Sep 14, 2015

I submitted a pull request for the same thing, just saw there already was one, my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants