6

I want summary count in .phtml file with cache enable.

2
  • 1
    where u want to get summery count, means product page or category page etc...? Commented Jan 1, 2020 at 13:35
  • I want summary count in footer same like header.
    – M2 Dev
    Commented Jan 1, 2020 at 13:38

1 Answer 1

9

You should get it with customer data. You can try to add the following code in your phtml file.

<script type="text/javascript">
    require([
        'Magento_Customer/js/customer-data'
    ], function (customerData) {
        'use strict';

        customerData.get('cart').subscribe(function (cartInfo) {
            console.log(cartInfo['summary_count']);
        }, this);
    });
</script>
4
  • 1
    Thanks for the answer, let me try this.
    – M2 Dev
    Commented Jan 1, 2020 at 13:52
  • 1
    Will it work for guest user also?
    – M2 Dev
    Commented Jan 1, 2020 at 13:53
  • 1
    yes it will work............. Commented Jan 1, 2020 at 13:54
  • 1
    Yes, Thanks Its working fine for me.
    – M2 Dev
    Commented Jan 1, 2020 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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