In this tutorial, we will show how to trigger the totals block refresh in the cart.

What is the totals block?

The totals block is the block that displays totals - subtotal, discount, shipping rates, taxes and grand total -

How to cause the totals to refresh in the cart

Sometimes, when working on JavaScript code that changes totals, you might want the totals block to refresh. In order to do that, merge the following piece of code with your js code:

require(
    [
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/cart/totals-processor/default'
   ],
    function(
        quote,
        totalsDefaultProvider
    ) {
        totalsDefaultProvider.estimateTotals(quote.shippingAddress());
    }
);

The totals block in Magento 2 cart is refreshing

Summing up

We just saw how to cause the totals block to refresh. If you have any questions about the code - please write me in comments.

1

Comments

Feb 12, 2018

Adrian

when i'm adding totals-processor/default in my js i get TypeError: options is undefined and price stop loading

Leave A Reply

Your email address will not be published.