Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 - How to get cart items total in header.phtml

Tags:

I am working with magento 2. I got php error when am using

echo Mage::helper(‘checkout/cart’)->getCart()->getItemsCount();

how to get cart item count in magento 2?

like image 863
Ragubathi U Avatar asked May 10 '16 09:05

Ragubathi U


2 Answers

    $counter = $this->helper('\Magento\Checkout\Helper\Cart'); 
    echo $counter->getItemsCount();
like image 195
Ragubathi U Avatar answered Sep 28 '22 03:09

Ragubathi U


Magento 2 provides 2 ways to show items count. One shows the number of individual items in the cart, while the other one shows the total count of items in the cart.

Let us say that cart helper is;

$helper = $this->helper('\Magento\Checkout\Helper\Cart');

When you do:

echo $counter->getItemsCount();

it will show the number of individual items in the cart.

If you want to show total items count, then use:

echo $counter->getSummaryCount();

like image 35
Mohit Kumar Arora Avatar answered Sep 28 '22 04:09

Mohit Kumar Arora