How to Reload Total Using JS on Cart / Checkout Page in Magento 2
If you are looking for a way to reload the total summary of the cart and checkout page in Magento 2 using JS, then you are in a right place. In this article we'll explain you how to reload the totals summary using JS on Cart / Checkout Page in Magento 2
Let's get started!!
Step 1: You need to add following code in your js file.
saveCopyzoom_out_mapdefine(
[
'ko',
'jquery',
'Magento_Checkout/js/model/cart/totals-processor/default',
'Magento_Checkout/js/model/cart/cache'
],
function (ko, $, defaultTotal, cartCache) {
'use strict';
return Component.extend({
initialize: function () {
this._super();
this.reloadTotal();
},
reloadTotal:function () {
cartCache.set('totals',null);
defaultTotal.estimateTotals();
}
});
}
);
In above code, you can see we've defined the below JS file. So, you need to define the same on your js file.
saveCopyzoom_out_map'Magento_Checkout/js/model/cart/totals-processor/default', 'Magento_Checkout/js/model/cart/cache'
Furthermore, you can see in the above code we've create the reloadTotal function and call it on initialize function. You can call the reloadTotal function as per your requirements in your file.
Or you can add the below lines on your code where you want to reload the total summary.
saveCopyzoom_out_mapcartCache.set('totals',null); defaultTotal.estimateTotals();
Step 2: Run the below commands.
saveCopyzoom_out_mapphp bin/magento setup:upgrade
Bingo!! we are done.
I hope this article helped you to find what you were looking for.
Bookmark it for your future reference. Do comment below if you have any other questions on that.
P.S. Do share this article with your team.
AI-Powered Recommended Articles
How to Use Javascript Mixins in Magento 2
Learn how to use mixins in Magento 2 to extend and customize JavaScript functionality.
Automatically Refresh Cache Using Cron in Magento 2
Set up a cron job in Magento 2 to automatically refresh your website's cache and ensure up-to-date content.
How to update the PriceBox cache in Magento 2.
Learn how to update the pricebox cache in Magento 2 for proper price rendering on your site.
Magento 2 - How to Display Minimum Order Amount Message on Minicart
Learn how to display a message for the minimum order amount in the mini cart on Magento 2 to encourage customers to meet the order threshold.
How to Use Event in Magento 2
Learn how to use events in Magento 2 to trigger custom functionality and extend store operations.
How to Add/Remove CSS and JS file in Magento 2
Learn how to add or remove CSS and JavaScript files in Magento 2 to manage your theme and layout.