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!
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
Kindly confirm if you have replaced the proper action into the code and that the controller file is available on that location as well.
Maybe the filename is the wrong section.xml. It should be sections.xml.
If I am not wrong
Yes the file name is “sections.xml”.
Hi!!
I have added product programatically on observer so how can I update the mini cart. could you please help in that case?
By adding from observer, the above code will not help you. You have to try alternative solutions.