Login Contact Us
My cart

Magento 2: Triggering totals refresh in cart

Feb 12, 2018
by Mexbs team
Magento Tutorials

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.