Skip to content

Commit 8648f52

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #18984: [Backport] Reload cart totals when cart data changes (by @tdgroot) - #18908: [Backport] fixed - Unable to select payment method according to country of the address at checkout time (by @rahulwebkul) Fixed GitHub Issues: - #18907: Unable to select payment method according to country of the address at checkout time (reported by @rahulwebkul) has been fixed in #18908 by @rahulwebkul in 2.2-develop branch Related commits: 1. f1b2360
2 parents 20a3ebe + 3b3dba9 commit 8648f52

File tree

3 files changed

+68
-46
lines changed

3 files changed

+68
-46
lines changed

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

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,71 @@ define([
1414
'use strict';
1515

1616
var rateProcessors = [],
17-
totalsProcessors = [];
17+
totalsProcessors = [],
1818

19-
quote.shippingAddress.subscribe(function () {
20-
var type = quote.shippingAddress().getType();
19+
/**
20+
* Estimate totals for shipping address and update shipping rates.
21+
*/
22+
estimateTotalsAndUpdateRates = function () {
23+
var type = quote.shippingAddress().getType();
2124

22-
if (
23-
quote.isVirtual() ||
24-
window.checkoutConfig.activeCarriers && window.checkoutConfig.activeCarriers.length === 0
25-
) {
26-
// update totals block when estimated address was set
27-
totalsProcessors['default'] = totalsDefaultProvider;
28-
totalsProcessors[type] ?
29-
totalsProcessors[type].estimateTotals(quote.shippingAddress()) :
30-
totalsProcessors['default'].estimateTotals(quote.shippingAddress());
31-
} else {
32-
// check if user data not changed -> load rates from cache
33-
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
34-
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
35-
cartCache.get('rates')
25+
if (
26+
quote.isVirtual() ||
27+
window.checkoutConfig.activeCarriers && window.checkoutConfig.activeCarriers.length === 0
3628
) {
37-
shippingService.setShippingRates(cartCache.get('rates'));
29+
// update totals block when estimated address was set
30+
totalsProcessors['default'] = totalsDefaultProvider;
31+
totalsProcessors[type] ?
32+
totalsProcessors[type].estimateTotals(quote.shippingAddress()) :
33+
totalsProcessors['default'].estimateTotals(quote.shippingAddress());
34+
} else {
35+
// check if user data not changed -> load rates from cache
36+
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
37+
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
38+
cartCache.get('rates')
39+
) {
40+
shippingService.setShippingRates(cartCache.get('rates'));
3841

39-
return;
42+
return;
43+
}
44+
45+
// update rates list when estimated address was set
46+
rateProcessors['default'] = defaultProcessor;
47+
rateProcessors[type] ?
48+
rateProcessors[type].getRates(quote.shippingAddress()) :
49+
rateProcessors['default'].getRates(quote.shippingAddress());
50+
51+
// save rates to cache after load
52+
shippingService.getShippingRates().subscribe(function (rates) {
53+
cartCache.set('rates', rates);
54+
});
4055
}
56+
},
4157

42-
// update rates list when estimated address was set
43-
rateProcessors['default'] = defaultProcessor;
44-
rateProcessors[type] ?
45-
rateProcessors[type].getRates(quote.shippingAddress()) :
46-
rateProcessors['default'].getRates(quote.shippingAddress());
58+
/**
59+
* Estimate totals for shipping address.
60+
*/
61+
estimateTotalsShipping = function () {
62+
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
63+
},
4764

48-
// save rates to cache after load
49-
shippingService.getShippingRates().subscribe(function (rates) {
50-
cartCache.set('rates', rates);
51-
});
52-
}
53-
});
54-
quote.shippingMethod.subscribe(function () {
55-
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
56-
});
57-
quote.billingAddress.subscribe(function () {
58-
var type = quote.billingAddress().getType();
65+
/**
66+
* Estimate totals for billing address.
67+
*/
68+
estimateTotalsBilling = function () {
69+
var type = quote.billingAddress().getType();
70+
71+
if (quote.isVirtual()) {
72+
// update totals block when estimated address was set
73+
totalsProcessors['default'] = totalsDefaultProvider;
74+
totalsProcessors[type] ?
75+
totalsProcessors[type].estimateTotals(quote.billingAddress()) :
76+
totalsProcessors['default'].estimateTotals(quote.billingAddress());
77+
}
78+
};
5979

60-
if (quote.isVirtual()) {
61-
// update totals block when estimated address was set
62-
totalsProcessors['default'] = totalsDefaultProvider;
63-
totalsProcessors[type] ?
64-
totalsProcessors[type].estimateTotals(quote.billingAddress()) :
65-
totalsProcessors['default'].estimateTotals(quote.billingAddress());
66-
}
67-
});
80+
quote.shippingAddress.subscribe(estimateTotalsAndUpdateRates);
81+
quote.shippingMethod.subscribe(estimateTotalsShipping);
82+
quote.billingAddress.subscribe(estimateTotalsBilling);
83+
customerData.get('cart').subscribe(estimateTotalsShipping);
6884
});

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ define([
3535
saveShippingInformation: function () {
3636
var payload;
3737

38-
if (!quote.billingAddress()) {
39-
selectBillingAddressAction(quote.shippingAddress());
40-
}
38+
/* Assign selected address every time buyer selects address*/
39+
selectBillingAddressAction(quote.shippingAddress());
4140

4241
payload = {
4342
addressInformation: {

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/model/cart/estimate-service.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,12 @@ define([
143143
});
144144
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals).toHaveBeenCalled();
145145
});
146+
147+
it('test subscribe when cart data was changed', function () {
148+
mocks['Magento_Customer/js/customer-data'].get('cart')({
149+
dataId: 2
150+
});
151+
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals).toHaveBeenCalled();
152+
});
146153
});
147154
});

0 commit comments

Comments
 (0)