Skip to content

Commit b6402aa

Browse files
committed
Merge branch 'ACP2E-1143' of https://github.com/magento-l3/magento2ce into PR-02142023
2 parents 4b5c1dc + 5949760 commit b6402aa

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,28 @@
44
*/
55

66
define([
7+
'underscore',
78
'Magento_Checkout/js/model/quote',
89
'Magento_Checkout/js/model/shipping-rate-processor/new-address',
910
'Magento_Checkout/js/model/cart/totals-processor/default',
1011
'Magento_Checkout/js/model/shipping-service',
1112
'Magento_Checkout/js/model/cart/cache',
1213
'Magento_Customer/js/customer-data'
13-
], function (quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData) {
14+
], function (_, quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData) {
1415
'use strict';
1516

1617
var rateProcessors = {},
1718
totalsProcessors = {},
1819

20+
/**
21+
* Cache shipping address until changed
22+
*/
23+
setShippingAddress = function () {
24+
var shippingAddress = _.pick(quote.shippingAddress(), cartCache.requiredFields);
25+
26+
cartCache.set('shipping-address', shippingAddress);
27+
},
28+
1929
/**
2030
* Estimate totals for shipping address and update shipping rates.
2131
*/
@@ -35,10 +45,10 @@ define([
3545
// check if user data not changed -> load rates from cache
3646
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
3747
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
38-
cartCache.get('rates')
48+
cartCache.get('rates') && !cartCache.isChanged('totals', quote.getTotals())
3949
) {
4050
shippingService.setShippingRates(cartCache.get('rates'));
41-
51+
quote.setTotals(cartCache.get('totals'));
4252
return;
4353
}
4454

@@ -51,7 +61,16 @@ define([
5161
// save rates to cache after load
5262
shippingService.getShippingRates().subscribe(function (rates) {
5363
cartCache.set('rates', rates);
64+
setShippingAddress();
5465
});
66+
67+
// update totals based on updated shipping address / rates changes
68+
if (cartCache.get('shipping-address') && cartCache.get('shipping-address').countryId &&
69+
cartCache.isChanged('shipping-address', quote.shippingAddress()) &&
70+
(!quote.shippingMethod() || !quote.shippingMethod()['method_code'])) {
71+
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
72+
cartCache.set('totals', quote.getTotals());
73+
}
5574
}
5675
},
5776

app/code/Magento/Multishipping/Test/Mftf/Test/StorefrontDisableMultishippingModeCheckoutOnBackToCartTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
</actionGroup>
5757

5858
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="goToShoppingCartFromMinicart"/>
59+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
60+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
61+
<waitForElementVisible time="30" selector="{{CheckoutCartSummarySection.total}}" stepKey="waitForTotalElement"/>
5962
<waitForPageLoad stepKey="waitForGrandTotalToLoad"/>
6063
<grabTextFrom selector="{{CheckoutPaymentSection.orderSummaryTotal}}" stepKey="grabTotal"/>
6164

app/code/Magento/SalesRule/Test/Mftf/Test/StorefrontCategoryRulesShouldApplyToGroupedProductWithInvisibleIndividualProductTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
<argument name="linkedProduct2Name" value="$createSecondSimpleProduct.name$"/>
107107
</actionGroup>
108108
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="openTheCartWithFirstAndSecondGroupedProducts"/>
109+
<waitForPageLoad stepKey="waitForGrandTotalToLoad"/>
110+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
111+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
112+
<waitForElementVisible time="30" selector="{{CheckoutCartSummarySection.total}}" stepKey="waitForTotalElement"/>
109113
<!-- Discount amount is applied for product from first category only -->
110114
<actionGroup ref="StorefrontCheckCartTotalWithDiscountCategoryActionGroup" stepKey="checkDiscountIsApplied">
111115
<argument name="subtotal" value="$1,000.00"/>

app/code/Magento/Tax/view/frontend/web/js/view/checkout/cart/totals/tax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([
2121
* @override
2222
*/
2323
ifShowValue: function () {
24-
if (parseInt(this.getPureValue()) === 0) { //eslint-disable-line radix
24+
if (this.isFullMode() && this.getPureValue() == 0) { //eslint-disable-line eqeqeq
2525
return isZeroTaxDisplayed;
2626
}
2727

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ define([
2020

2121
var injector = new Squire(),
2222
rates = 'flatrate',
23+
totals = {
24+
tax: 0.1,
25+
totals: 10
26+
},
2327
mocks = {
2428
'Magento_Checkout/js/model/quote': {
2529
shippingAddress: ko.observable(),
2630
isVirtual: function () {},
2731
billingAddress: ko.observable(),
28-
shippingMethod: ko.observable()
29-
32+
shippingMethod: ko.observable(),
33+
setTotals: function () {},
34+
getTotals: function () {}
3035
},
3136
'Magento_Checkout/js/model/shipping-rate-processor/new-address': {
3237
getRates: jasmine.createSpy()
@@ -42,7 +47,7 @@ define([
4247
},
4348
'Magento_Checkout/js/model/cart/cache': {
4449
isChanged: function () {},
45-
get: jasmine.createSpy().and.returnValue(rates),
50+
get: jasmine.createSpy().and.returnValues(rates, rates, totals),
4651
set: jasmine.createSpy()
4752
},
4853
'Magento_Customer/js/customer-data': {
@@ -88,19 +93,22 @@ define([
8893

8994
it('test subscribe when shipping address wasn\'t changed for not virtual quote', function () {
9095
spyOn(mocks['Magento_Checkout/js/model/quote'], 'isVirtual').and.returnValue(false);
91-
spyOn(mocks['Magento_Checkout/js/model/cart/cache'], 'isChanged').and.returnValue(false);
96+
spyOn(mocks['Magento_Checkout/js/model/quote'], 'getTotals').and.returnValue(false);
97+
spyOn(mocks['Magento_Checkout/js/model/cart/cache'], 'isChanged').and.returnValues(false, false);
9298
spyOn(mocks['Magento_Checkout/js/model/shipping-service'], 'setShippingRates');
99+
spyOn(mocks['Magento_Checkout/js/model/quote'], 'setTotals');
93100
mocks['Magento_Checkout/js/model/quote'].shippingAddress({
94101
id: 2,
95102
getType: function () {
96103
return 'address_type_test';
97104
}
98105
});
99106
expect(mocks['Magento_Checkout/js/model/shipping-service'].setShippingRates).toHaveBeenCalledWith(rates);
100-
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals).not
101-
.toHaveBeenCalled();
102-
expect(mocks['Magento_Checkout/js/model/shipping-rate-processor/new-address'].getRates)
107+
expect(mocks['Magento_Checkout/js/model/quote'].setTotals).toHaveBeenCalledWith(totals);
108+
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals)
103109
.not.toHaveBeenCalled();
110+
expect(mocks['Magento_Checkout/js/model/shipping-rate-processor/new-address'].getRates)
111+
.toHaveBeenCalled();
104112
});
105113

106114
it('test subscribe when shipping address was changed for virtual quote', function () {
@@ -114,7 +122,7 @@ define([
114122
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals)
115123
.toHaveBeenCalled();
116124
expect(mocks['Magento_Checkout/js/model/shipping-rate-processor/new-address'].getRates)
117-
.not.toHaveBeenCalled();
125+
.toHaveBeenCalled();
118126
});
119127

120128
it('test subscribe when shipping address was changed for not virtual quote', function () {
@@ -133,6 +141,8 @@ define([
133141
.not.toHaveBeenCalledWith(rates);
134142
expect(mocks['Magento_Checkout/js/model/cart/cache'].set).not.toHaveBeenCalled();
135143
expect(mocks['Magento_Checkout/js/model/shipping-rate-processor/new-address'].getRates).toHaveBeenCalled();
144+
expect(mocks['Magento_Checkout/js/model/cart/totals-processor/default'].estimateTotals)
145+
.toHaveBeenCalled();
136146
});
137147

138148
it('test subscribe when shipping method was changed', function () {

0 commit comments

Comments
 (0)