I am unable to get summary count with php code when cache is enable.

I used below code.

$helper = $this->helper('\Magento\Checkout\Helper\Cart');
echo $helper->getSummaryCount();
  • instead of $this->helper('\Magento\Checkout\Helper\Cart'); you should try it $this->helper(Magento\Checkout\Helper\Cart::class); make sure clearing cache after making this change. – Aman Alam Dec 30 '19 at 12:53

You can't with cache enabled, all files aren't re-interpreted.

You should get it with javascript. You can try to add the following code in your phtml file (the following example is to show you the way) :

<script type="text/javascript">
    ], function (customerData) {
        'use strict';

        customerData.get('cart').subscribe(function (cartInfo) {
        }, this);

This code will print nothing where there isn't product in cart, and cart count when there is products.
It will be triggered every times that the cart is updated.

|improve this answer|||||

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.