Magento – How to reload order summary section on payment page in Magento 2

magento2

I need to reload order summary section on selecting the payment method in magento 2

Best Answer

Create a file called requirejs-config.js within your module-theme folder (don't do this in vendor files).

In there add:

var config = {
   map: {
    '*': {
        custom:'Magento_Theme/js/custom',
    }
  }
};

Then create a file called custom.js under module-theme/web/js (Again not in your vendor files). And in there add:

define([
'jquery',
'Magento_Checkout/js/action/get-totals',
'Magento_Customer/js/customer-data'
 ], function ($, getTotalsAction, customerData) {
    $(document).ready(function(){

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

This should refresh the cart page when the page loads. If you want this to happen at a certain point just listen for a change event such as:

$(document).on('change', 'input[name$="[qty]"]', function(){
    var deferred = $.Deferred();
    getTotalsAction([], deferred);
});

Hope this helps