{"id":63937,"date":"2016-11-18T11:52:12","date_gmt":"2016-11-18T11:52:12","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=63937"},"modified":"2025-12-04T06:11:38","modified_gmt":"2025-12-04T06:11:38","slug":"update-mini-cart-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/","title":{"rendered":"Update Mini Cart Magento 2"},"content":{"rendered":"<p>In this guide, we\u2019ll explore how to update the mini cart in Magento 2 with practical steps and useful insights.<br \/>\nIn Magento 2 many times it happens, You changed something in cart but it does not reflects in mini cart.<br \/>\nIt happens when you try to change and update cart items programmatically.<\/p>\n<p><strong>There can be two types of situation.<\/strong><\/p>\n<ul>\n<li>When you are updating cart by submitting form.<\/li>\n<li>When you are updating cart without submitting form.<\/li>\n<\/ul>\n<p>Don\u2019t miss our blog \u201c<a href=\"https:\/\/webkul.com\/blog\/how-to-show-additional-data-on-mini-cart-in-magento-2\/\">Show Additional Data on Mini-cart in Magento 2<\/a>,\u201d which walks you through adding extra, customized data to the mini cart.<\/p>\n<h2>Update mini cart when you are submitting a form<\/h2>\n<p>Magento provides a way to update minicart if you are submitting a form.<br \/>\nFirst of all create <strong>sections.xml<\/strong> file in <strong>&#8216;etc\/frontend&#8217;<\/strong> folder in your module.<br \/>\nNow write following code snippet in sections.xml file<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\"?&gt;\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Customer:etc\/sections.xsd\"&gt;\n    &lt;action name=\"modulename\/controler\/addProduct\"&gt;\n        &lt;section name=\"cart\"\/&gt;\n    &lt;\/action&gt;\n&lt;\/config&gt;<\/pre>\n<p><strong>action name<\/strong> : action name is controller where you are submitting form.<br \/>\nSo Use this approach whenever you are dealing with a form.<br \/>\nExample of this situation may be when you want to set custom price of product in your own controller.<br \/>\n<strong>This approach\u00a0will work when you are using POST or PUT form submitting. It will also work for AJAX request.<\/strong><\/p>\n<h2>Update mini cart when you are not submitting a form<\/h2>\n<p>In some situations you want to update cart and you don&#8217;t\u00a0want to submit any form.<\/p>\n<p>In these type of situations you can not use sections.xml file because you are not submitting a form.<\/p>\n<p>So for these type of situations you can use following code in template file.<\/p>\n<pre class=\"brush:php\">&lt;script&gt;\n    require([\n        'Magento_Customer\/js\/customer-data'\n    ], function (customerData) {\n        var sections = ['cart'];\n        customerData.invalidate(sections);\n        customerData.reload(sections, true);\n    });\n&lt;\/script&gt;<\/pre>\n<p>So use this code snippet in phtml file and minicart will be updated.<br \/>\nExample of this situation may be when you want to add and update items in cart on cart view and checkout page.<br \/>\nSo using these two approaches you can update mini cart in any type of situation.<\/p>\n<p>If you have any issue or query, comment below.<\/p>\n<p>You may also check our quality <a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noopener\">Adobe Commerce Extensions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we\u2019ll explore how to update the mini cart in Magento 2 with practical steps and useful insights. In Magento 2 many times it happens, You changed something in cart but it does not reflects in mini cart. It happens when you try to change and update cart items programmatically. There can be <a href=\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":21,"featured_media":63938,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[1060,2070,3970,3969],"class_list":["post-63937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-cart","tag-magento2","tag-mini-cart","tag-update-mini-cart"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Update Mini Cart After Custom Calculation in Magento2<\/title>\n<meta name=\"description\" content=\"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Update Mini Cart After Custom Calculation in Magento2\" \/>\n<meta property=\"og:description\" content=\"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rahul0989\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-18T11:52:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-04T06:11:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rahul Mahto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rahul Mahto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\"},\"author\":{\"name\":\"Rahul Mahto\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f\"},\"headline\":\"Update Mini Cart Magento 2\",\"datePublished\":\"2016-11-18T11:52:12+00:00\",\"dateModified\":\"2025-12-04T06:11:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\"},\"wordCount\":335,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png\",\"keywords\":[\"cart\",\"Magento2\",\"Mini Cart\",\"Update Mini Cart\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\",\"name\":\"How to Update Mini Cart After Custom Calculation in Magento2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png\",\"datePublished\":\"2016-11-18T11:52:12+00:00\",\"dateModified\":\"2025-12-04T06:11:38+00:00\",\"description\":\"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png\",\"width\":825,\"height\":260,\"caption\":\"Update Mini Cart\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Update Mini Cart Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f\",\"name\":\"Rahul Mahto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Rahul Mahto\"},\"sameAs\":[\"http:\/\/webkul.com\",\"https:\/\/www.facebook.com\/rahul0989\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/rahul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Update Mini Cart After Custom Calculation in Magento2","description":"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to Update Mini Cart After Custom Calculation in Magento2","og_description":"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2","og_url":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_author":"https:\/\/www.facebook.com\/rahul0989","article_published_time":"2016-11-18T11:52:12+00:00","article_modified_time":"2025-12-04T06:11:38+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png","type":"image\/png"}],"author":"Rahul Mahto","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Rahul Mahto","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/"},"author":{"name":"Rahul Mahto","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f"},"headline":"Update Mini Cart Magento 2","datePublished":"2016-11-18T11:52:12+00:00","dateModified":"2025-12-04T06:11:38+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/"},"wordCount":335,"commentCount":3,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png","keywords":["cart","Magento2","Mini Cart","Update Mini Cart"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/","url":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/","name":"How to Update Mini Cart After Custom Calculation in Magento2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png","datePublished":"2016-11-18T11:52:12+00:00","dateModified":"2025-12-04T06:11:38+00:00","description":"How to Update Mini Cart After Custom Calculation in Magento2, How to Update Mini Cart After Custom Calculation in Magento2","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet.png","width":825,"height":260,"caption":"Update Mini Cart"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/update-mini-cart-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Update Mini Cart Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3002e6bca8362f6cf1c61b2663496c4f","name":"Rahul Mahto","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b0def172ef24ea3f7319500afbb65af8012023ba5c143982a4c958b2fb58ee0d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Rahul Mahto"},"sameAs":["http:\/\/webkul.com","https:\/\/www.facebook.com\/rahul0989"],"url":"https:\/\/webkul.com\/blog\/author\/rahul\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=63937"}],"version-history":[{"count":26,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63937\/revisions"}],"predecessor-version":[{"id":515233,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63937\/revisions\/515233"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/63938"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=63937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=63937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=63937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}