2

I want to display cart items total to my header cart link.

I have get some reference from https://magento.stackexchange.com/ but not any solution work for me.

Some are works but only it will display on cart page header link. It will display on all pages if cache is display. cart total not showing on other pages header link when cache is enable.

Any one have done this. Please help.

4

You can display cart items sub-total to header minicart link.

Add below code to minicart.phtml to display cart items total

<span data-bind="html: getCartParam('subtotal')"></span>

php bin/magento cache:clean
  • 1
    Thanks. Best answer bro. It also update data after added to cart using ajax. Thanks a lot – Asish Hira Jun 23 '17 at 11:27
  • Want to add cart count on product listing page. Please let us know how can we achieve this? – Vish Jun 15 '18 at 13:21
1

Get total items, total quantity, subtotal and grand total in cart

Please add the following code in your header.phtml file

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

echo $totalItems = $cart->getQuote()->getItemsCount();
echo $totalQuantity = $cart->getQuote()->getItemsQty();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

echo $subTotal = $cart->getQuote()->getSubtotal();
echo $grandTotal = $cart->getQuote()->getGrandTotal();
  • This code not working on all other pages when cache is enable. you can see my answer, best solution for that. – Suresh Chikani Dec 14 '16 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.