How to Update Mini Cart in Magento 2
Magento 2 offers a mini cart feature that allows the visitors to conveniently check their cart items and other details without having to leave the current page and load the cart page.
Mini cart improves the on-site experience of any online store. However, Magento developers have noted an issue of mini cart not refreshing when a visitor adds or removes an item or make any changes in the cart. You can also show additional data in Magento 2 Mini Cart to show shipping charge, discount or tax information etc.
This is surely a blow to the user experience and needs a solution!
Here’s the programmatic solution to overcome this issue and update mini cart in Magento 2.
Method to update mini cart in Magento 2:
1 2 3 4 5 6 7 |
require([ 'Magento_Customer/js/customer-data' ], function (customerData) { var sections = ['cart']; customerData.invalidate(sections); customerData.reload(sections, true); }); |
Any doubts? Use the Comments section below to mention them. I’ll help you out.
Do share the solution with Magento community via social media.
Thank you.
Likewise in Magento 2 restrict quantity update from minicart which will be helpful to you when you have set condition of limiting the order quantity.
Related Posts:
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
Thanks for sharing, the same thing happens on our website. The shopping cart is not updated when a customer logs in.
Where is the code placed?
Thank you very much for your help and sharing.
Hello,
Place the code in update JS and for which you’ll have to override JS.
Or else in the theme JS.
Thanks.