Question

I am trying to display the number of items currently in my cart, however not getting any result. In magento 1 we just just add the following to our phtml file and it will just echo the no. of items in cart.

Mage::getModel(‘checkout/cart’)->getQuote()->getItemsCount();

This of course does not work in in magento 2 (version 2.0.2). Within my custom html file. I just need to echo just the number, just like you get when get a number on the mini cart. This is the section of code i need to put it in

<span class="cart-text"><strong>Basket:</strong>
    <span class="cart-count">??????</span> item(s)
</span>

I need to put the number in replace of the question marks. This may be a simple question, however i am still in the early stages of my learning curve, help is greatly appreciated. Thanks

Was it helpful?

Solution

try this

$helper = $this->helper('\Magento\Checkout\Helper\Cart');
 echo $helper->getItemsCount();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top