How to Fix programmatically mini cart not updated issue in Magento 2

Mini Cart Not Updated when Programmatically Change in Cart Quote

Magento is one of made for E-commerce CMS that knows for its functionality, flexible code structure and performance. Among that, Magento comes with an Enhanced shopping cart features as well as a mini shopping cart widget that appears in the upper-right corner of the store. Using this mini cart customer can quickly take a look at cart items and can update or reduce product quantity. Generally, when you add any products to cart it will be automatically listed on the cart page as well as widget page. But in a recent version of Magento 2.1.x, there is an issue while we add products to cart and click view cart option it shows that cart is empty. However, it shows a successful message instantly. Even this issue is raised by one of the developers in Magento Github.

After working on this issue for a while, finally we found a solution by overriding ‘sections.xml’ file on store frontend using a custom extension. Simply create a file using following code inside your extension folder.
app\code\Vendor\Extension\etc\frontend\sections.xml

<pre class="lang:default decode:true">
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="extension/controller/action">
        <section name="cart"/>
    </action>
</config>
</pre>

In this action parameter name, you have to pass the full action (For ex. checkout/cart/add ) in which cart is updated. It means you programmatically delete or add a product to cart to the shopping cart.

Lastly, Comment down below if you face any issue while using this code.

Happy Coding!

Previous Article

How to fix issue of saving custom customer attribute value programmatically in Magento 2

Next Article

How to disable Ajax Add to Cart on Product page in Magento 2

Write a Comment
  1. Hello,

    I created new file “section.xml”in my custom extension. But it is not working. Can you please help me to solve this issue

  2. Hi!!
    I have added product programatically on observer so how can I update the mini cart. could you please help in that case?

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨