Skip to content

Commit 4c624e9

Browse files
committed
ACP2E-1143: trigger tax / subtotal estimates refresh on shipping address updates
1 parent c7dd8ca commit 4c624e9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/cart/estimate-service.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ define([
99
'Magento_Checkout/js/model/cart/totals-processor/default',
1010
'Magento_Checkout/js/model/shipping-service',
1111
'Magento_Checkout/js/model/cart/cache',
12-
'Magento_Customer/js/customer-data'
13-
], function (quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData) {
12+
'Magento_Customer/js/customer-data',
13+
'Magento_Checkout/js/checkout-data',
14+
'Magento_Checkout/js/action/select-shipping-method'
15+
], function (quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData, checkoutData, selectShippingMethodAction) {
1416
'use strict';
1517

1618
var rateProcessors = {},
@@ -35,8 +37,9 @@ define([
3537
// check if user data not changed -> load rates from cache
3638
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
3739
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
38-
cartCache.get('rates') && cartCache.get('totals')
40+
cartCache.get('rates') //&& cartCache.get('totals')
3941
) {
42+
4043
shippingService.setShippingRates(cartCache.get('rates'));
4144
quote.setTotals(cartCache.get('totals'));
4245
return;
@@ -53,8 +56,12 @@ define([
5356
cartCache.set('rates', rates);
5457
});
5558

56-
// update totals based on shipping address / rates changes
57-
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
59+
// update totals based on updated shipping address / rates changes
60+
if (cartCache.get('address') &&
61+
(!quote.shippingMethod() || !quote.shippingMethod()['method_code'])
62+
) {
63+
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
64+
}
5865
}
5966
},
6067

@@ -80,7 +87,9 @@ define([
8087
}
8188
};
8289

83-
90+
/*if (!quote.shippingMethod() && cartCache.get('rates')) {
91+
selectShippingMethodAction(cartCache.get('rates')[0]);
92+
}*/
8493
quote.shippingAddress.subscribe(estimateTotalsAndUpdateRates);
8594
quote.shippingMethod.subscribe(estimateTotalsShipping);
8695
quote.billingAddress.subscribe(estimateTotalsBilling);

0 commit comments

Comments
 (0)