Many websites show a “total number of items in your basket”. So, how do you get that information out of Magento if you’re not in the checkout process?

You can simply call the Mage Helper file checkout/cart.

If all you’re after is a total number, all you need is:

This code grabs the helper object, gets the current cart object, and then calls the Magento count function on that.

If you want to do something with the items, then you’ll need to return the items, rather than the counter. To do this, you need to look at the helper checkout/session instead.

Something along the lines of:

If you wanted to get the total for the basket – so that it could be displayed elsewhere on your site, then you can get this from the checkout/cart class. Note, we don’t get this from the helper.

Simply call:

Image Credit: i k o