Skip to content

Commit 74867e1

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #571 from magento-folks/MAGETWO-42130
[Folks] Bug fix (P0 issue)
2 parents 6ba36cf + 495c23e commit 74867e1

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

Diff for: app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ define(
2929
}
3030

3131
addressData.region = {
32-
region_id: null,
33-
region_code: null,
32+
region_id: addressData.region_id,
33+
region_code: addressData.region_code,
3434
region: regionName
3535
};
3636

Diff for: app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ define([
1818
'Magento_Checkout/js/action/select-payment-method',
1919
'Magento_Checkout/js/model/address-converter',
2020
'Magento_Checkout/js/action/select-billing-address',
21-
'Magento_Checkout/js/action/create-billing-address'
21+
'Magento_Checkout/js/action/create-billing-address',
22+
'underscore'
2223
], function (
2324
addressList,
2425
quote,
@@ -30,7 +31,8 @@ define([
3031
selectPaymentMethodAction,
3132
addressConverter,
3233
selectBillingAddress,
33-
createBillingAddress
34+
createBillingAddress,
35+
_
3436
) {
3537
'use strict';
3638

@@ -39,9 +41,10 @@ define([
3941
if (checkoutData.getShippingAddressFromData()) {
4042
var address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData());
4143
selectShippingAddress(address);
44+
} else {
45+
this.resolveShippingAddress();
4246
}
43-
this.resolveShippingAddress(true);
44-
if (quote.isVirtual) {
47+
if (quote.isVirtual()) {
4548
if (checkoutData.getBillingAddressFromData()) {
4649
address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getBillingAddressFromData());
4750
selectBillingAddress(address);
@@ -61,7 +64,6 @@ define([
6164
},
6265

6366
applyShippingAddress: function (isEstimatedAddress) {
64-
6567
if (addressList().length == 0) {
6668
var address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData());
6769
selectShippingAddress(address);
@@ -104,40 +106,37 @@ define([
104106

105107
resolveShippingRates: function (ratesData) {
106108
var selectedShippingRate = checkoutData.getSelectedShippingRate();
107-
var rateIsAvailable = false;
109+
var availableRate = false;
108110

109111
if (ratesData.length == 1) {
110112
//set shipping rate if we have only one available shipping rate
111113
selectShippingMethodAction(ratesData[0]);
112114
return;
113115
}
114116

115-
if(quote.shippingMethod()) {
116-
rateIsAvailable = ratesData.some(function (rate) {
117+
if (quote.shippingMethod()) {
118+
availableRate = _.find(ratesData, function (rate) {
117119
return rate.carrier_code == quote.shippingMethod().carrier_code
118120
&& rate.method_code == quote.shippingMethod().method_code;
119121
});
120122
}
121123

122-
if (!rateIsAvailable && selectedShippingRate) {
123-
rateIsAvailable = ratesData.some(function (rate) {
124-
if (rate.carrier_code + "_" + rate.method_code == selectedShippingRate) {
125-
selectShippingMethodAction(rate);
126-
return true;
127-
}
128-
return false;
129-
124+
if (!availableRate && selectedShippingRate) {
125+
availableRate = _.find(ratesData, function (rate) {
126+
return rate.carrier_code + "_" + rate.method_code === selectedShippingRate;
130127
});
131128
}
132129

133-
if (!rateIsAvailable && window.checkoutConfig.selectedShippingMethod) {
134-
rateIsAvailable = true;
130+
if (!availableRate && window.checkoutConfig.selectedShippingMethod) {
131+
availableRate = true;
135132
selectShippingMethodAction(window.checkoutConfig.selectedShippingMethod);
136133
}
137134

138135
//Unset selected shipping method if not available
139-
if (!rateIsAvailable) {
136+
if (!availableRate) {
140137
selectShippingMethodAction(null);
138+
} else {
139+
selectShippingMethodAction(availableRate);
141140
}
142141
},
143142

Diff for: app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ define(
4747
this._super();
4848

4949
this.shippingRates.subscribe(function (rates) {
50+
self.shippingRateGroups([]);
5051
_.each(rates, function (rate) {
5152
var carrierTitle = rate['carrier_title'];
5253

Diff for: app/code/Magento/Customer/view/frontend/web/js/model/customer/address.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define([], function() {
1414
customerAddressId: addressData.id,
1515
email: addressData.email,
1616
countryId: addressData.country_id,
17-
regionId: addressData.region.region_id,
17+
regionId: addressData.region_id,
1818
regionCode: addressData.region.region_code,
1919
region: addressData.region.region,
2020
customerId: addressData.customer_id,

Diff for: dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Shipping.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ public function openEstimateShippingAndTax()
7474
*
7575
* @param array $shipping
7676
* @return void
77+
* @throws \Exception
7778
*/
7879
public function selectShippingMethod(array $shipping)
7980
{
8081
$selector = sprintf($this->shippingMethod, $shipping['shipping_service'], $shipping['shipping_method']);
8182
if (!$this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->isVisible()) {
8283
$this->openEstimateShippingAndTax();
8384
}
84-
$this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->click();
85+
86+
$element = $this->_rootElement->find($selector, Locator::SELECTOR_XPATH);
87+
if (!$element->isDisabled()) {
88+
$element->click();
89+
} else {
90+
throw new \Exception("Unable to set value to field '$selector' as it's disabled.");
91+
}
8592
}
8693

8794
/**
@@ -95,8 +102,13 @@ public function fillEstimateShippingAndTax(Address $address)
95102
$this->openEstimateShippingAndTax();
96103
$data = $address->getData();
97104
$mapping = $this->dataMapping(array_intersect_key($data, array_flip($this->estimationFields)));
98-
$this->_fill($mapping, $this->_rootElement);
99-
$this->waitForUpdatedShippingMethods();
105+
106+
// Test environment may become unstable when form fields are filled in a default manner.
107+
// Imitating behavior closer to the real user.
108+
foreach ($mapping as $field) {
109+
$this->_fill([$field], $this->_rootElement);
110+
$this->waitForUpdatedShippingMethods();
111+
}
100112
}
101113

102114
/**

0 commit comments

Comments
 (0)