I'm using Magento CE 2.3.4. I used a custom theme for my website. In my top menu template, I tried this code to show my minicart and mini item quantity number:

$counter = $this->helper('\Magento\Checkout\Helper\Cart');
$total = $counter->getSummaryCount();
<i class="fas fa-shopping-cart"></i>
<?php if($total) : ?>
    <span class="count-cart-item"><?php echo $total; ?></span>
<?php endif; ?>

It's work fine when I disable full page cache and block html cache, I added product to cart and it update and show quatity correctly. But when I enable full cache, the quantity number in minicart is not updated.

If I go to cache management and flush cache, refresh page, it show correctly. Here is an image about this problem for clearly:

enter image description here

Hope you can give me a solution for this!

Thank you very much!

  • go to your default.xml and make header.phtml or minicart.phtml "cacheable='false'" using layout. It is cache issue. Apr 16 '20 at 5:06
  • I added to my default.xml bui it's not work
    – Tomato
    Apr 16 '20 at 8:16
  • okay, so now basically you need to disable caching(hole punching) for minicart block.Try minicart block as => cacheable='false' Apr 16 '20 at 11:22

Try following code

$counter = $this->helper('\Magento\Checkout\Helper\Cart'); 
echo $counter->getItemsCount();
  1. getItemsCount() -- return shopping cart items count means how many sku add to shopping cart.
  2. getSummaryCount() -- return shopping cart items summary (suppose you add sku1 6 qty and sku2 3 qty = total 9 qty return)
  • Both 2 methods not work for me! The minicart number still not update.
    – Tomato
    Apr 16 '20 at 7:08
  • have you used any extension?
    – Jinesh
    Apr 16 '20 at 7:45
  • check console log and log file if you getting any errors
    – Jinesh
    Apr 16 '20 at 7:47

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.