1

We have a single flat shipping rate that we want to be pre-selected on the shipping step of the checkout and to appear in the totals section. I have overridden the Magento_Checkout/js/view/summary/abstract-total.js and replaced isFullMode with

isFullMode: function() {
    return this.getTotals();
}

so that this section shows on that step, as it is disabled by default.

However, the totals section is still shown with the shipping rate as 0 Totals section

even though the shipping rate is shown and is already selected Shipping Options

Also, clicking on the radio button does not update the totals. I had initially thought that the totals section might be bound to the radio group using knockout for the selection from multiple rate shipping and re-calculation of the totals.

What do I need to do to get the correct preselected shipping rate cost into the totals section along with the correct calculation of the grand total?

2

For anyone also encountering this issue, this is how I got the totals section to update with the correct recalculated totals based upon selection of the shipping method.

Create a copy of /module-checkout/view/frontend/web/js/view/summary/shipping.js to your solution and override the default with your copy.

Add the Magento_Checkout/js/model/cart/estimate-service to the list of dependencies.

... done

How/why this works

On initialisation, the estimation service subscribes to quote.shippingMethod and when the page loads the quote.shippingMethod is updated with the default selection, which is the configured flat rate shipping. This update then notifies the estimate service which then recalculates the totals based upon the new shipping rate and this then updates the totals.

Final thoughts

Considering that updating cart totals upon selection of a different shipping method is quite common in ecommerce I find it a little odd that this is not wired up in vanilla magento 2, even when the totals section is disabled by default on the shipping step. I had to dig around in the cart page, and the plethora of related knockout files, to find why it seemed to work fine in calculating the totals whereas the shipping step in checkout did not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.