Site icon MageComp Blog

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!

Exit mobile version