3

I have a javascript function to add the product to the cart, but the problem is I need to refresh the page to see if the mini cart updated, in Magento 2 I use this function to update this mini cart, it seems pretty simple

<script>
    require([
        'Magento_Customer/js/customer-data'
    ], function (customerData) {
        var sections = ['cart'];
        customerData.invalidate(sections);
    });
</script>

Is there a way just to update mini cart in Magento 1.9 using javascript?

1

Magento 1 is not using browser local storage as Magento 2 does. Therefor, to update the minicart without refreshing the page you need to create an ajax request that would retrieve the HTML of the minicart and insert it into the block.

To do so you need to create a new controller or override the default controller to accept an ajax request and return only the minicart content as response.

There's already a script that refreshes the minicart after a product has been removed or updated.

If you look into the RWD theme, more specifically in this file: skin/frontend/rwd/default/js/minicart.js you will find the methods to do it.

Hope this helps

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.