Magento – Magento2 How to reload checkout page summary

checkoutmagento2

I am using Magento2.1.9 when I am going to the checkout page, order summary reloaded default magento's way so I used a js to our custom module added below code into it

var deferred = $.Deferred();
getTotalsAction([], deferred);

After that applied all commands but not working in reload order summary if any one idea reply me I have try to in other stack solution regarding this but not getting success.

Best Answer

I used one of the very good tutorial for this purpose

you need to add following code in your js file

/*browser:true*/
/*global define*/
define(
    [
        '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({
            updateamount:function () {//your function to update amount
                //your code to update amount
                //after successfull execution you need to add these lines.
                cartCache.set('totals',null);
                defaultTotal.estimateTotals();
            }
        });
    }
);

cartCache.set(‘totals’, null) : set the cart total to calculate totals again, if not using this line then estimateTotals() returns the totals for cache.

defaultTotal.estimateTotals(): executing the process to calculate totals.

Reference: https://webkul.com/blog/update-cart-totals-by-js-on-checkout-page-magento2/

I hope this will help