Categories: General

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

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!

Click to rate this post!
[Total: 25 Average: 4]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

1 day ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

5 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago