Magento – Magento 2 : Update shipping price in checkout summary by default on shipping step when there is only one shipping method available

magento2

I need to update checkout summary with shipping price by default when only one shipping method is available on shipping step.
Currently shipping price is updated when I move on to payment step.

If someone can help then it will helpful, thanks in advance.

enter image description here

enter image description here

Best Answer

After some research got the solution to set shipping price to summary on checkout if there is only one shipping method available.

For this, need to extend "/vendor/magento/module-checkout/view/frontend/web/js/view/summary/shipping.js"

Have to define 'Magento_Checkout/js/model/cart/estimate-service' and pass dependency estimateService into function.

Comment out this line var price = this.totals().shipping_amount; under function getValue: function() and add following two lines after that.

var shippingMethod = quote.shippingMethod();
var price =  shippingMethod.amount;

I am adding screen shot of entire file /module-checkout/view/frontend/web/js/view/summary/shipping.js how it looks after extending and editing.

enter image description here

Related Topic