Magento 2 – Get Number of Items in Cart

cartmagento2quote

I am trying to get items quantity from the cart.

I tried using this but it responded with unexpected results:

<?php
$helper = $this->helper('\Magento\Checkout\Helper\Cart');
echo $helper->getItemsCount(); ?>
?>

That returns a number of products in the cart but not the number of items.

Example:

Product 1 – Quantity in cart (2)

Product 2 – Quantity in cart (4)

The above would give me a result of 2 but I would expect 6.

How can I achieve the above?

Magento ver. 2.2.4

Best Answer

$helper = $this->helper('\Magento\Checkout\Helper\Cart');
echo $helper->getSummaryCount();
Related Topic