3

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.

Suresh Chikani
  • 15,836
  • 11
  • 62
  • 99
  • http://magento.stackexchange.com/questions/96540/magento-2-how-to-override-mini-cart-default-template-html-file & http://magento.stackexchange.com/questions/121271/magento-2-get-cart-quote-total-in-minicart-phtml Will help you out. Please give ur feedback after applying – Jackson Dec 07 '16 at 02:10
  • Already try but not success when cache is enable. – Suresh Chikani Dec 07 '16 at 08:45

2 Answers2

8

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
Suresh Chikani
  • 15,836
  • 11
  • 62
  • 99
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();
Abhinav Singh
  • 2,592
  • 15
  • 14