Skip to content

Commit d78f8d2

Browse files
author
Stanislav Idolov
authored
ENGCOM-584: #13231: Default State or Province is not pre-selected in the Estimate Shipping and Tax #1258
2 parents 0f80891 + 981d589 commit d78f8d2

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ define([
1717
*/
1818
return function (addressData) {
1919
var identifier = Date.now(),
20+
countryId,
2021
regionId;
2122

22-
if (addressData.region && addressData.region['region_id']) {
23-
regionId = addressData.region['region_id'];
24-
} else if (addressData['country_id'] && addressData['country_id'] == window.checkoutConfig.defaultCountryId) { //eslint-disable-line
25-
regionId = window.checkoutConfig.defaultRegionId || undefined;
23+
countryId = addressData['country_id'] || addressData.countryId;
24+
25+
if (countryId) {
26+
if (addressData.region && addressData.region['region_id']) {
27+
regionId = addressData.region['region_id'];
28+
} else if (countryId === window.checkoutConfig.defaultCountryId) {
29+
regionId = window.checkoutConfig.defaultRegionId;
30+
}
31+
} else {
32+
countryId = window.checkoutConfig.defaultCountryId;
33+
regionId = window.checkoutConfig.defaultRegionId;
2634
}
2735

2836
return {
2937
email: addressData.email,
30-
countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
31-
regionId: regionId || addressData.regionId,
38+
countryId: countryId,
39+
regionId: regionId,
3240
regionCode: addressData.region ? addressData.region['region_code'] : null,
3341
region: addressData.region ? addressData.region.region : null,
3442
customerId: addressData['customer_id'] || addressData.customerId,

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/model/new-customer-address.test.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ define([
1414
beforeEach(function () {
1515

1616
window.checkoutConfig = {
17-
defaultCountryId: 'US'
17+
defaultCountryId: 'US',
18+
defaultRegionId: 1
1819
};
1920

2021
newCustomerAddress = NewCustomerAddress;
@@ -27,6 +28,7 @@ define([
2728
it('Check on empty object.', function () {
2829
var expected = {
2930
countryId: 'US',
31+
regionId: 1,
3032
regionCode: null,
3133
region: null
3234
};
@@ -46,27 +48,28 @@ define([
4648
expect(result.canUseForBilling()).toBeTruthy();
4749
});
4850

49-
it('Check on regionId with region object in address data.', function () {
51+
it('Check on regionId with country object in address data.', function () {
5052
var result = newCustomerAddress({
51-
region: {
52-
'region_id': 1
53-
}
53+
'country_id': 'CA'
5454
}),
5555
expected = {
56-
countryId: 'US',
57-
regionId: 1
56+
countryId: 'CA',
57+
regionCode: null,
58+
region: null
5859
};
5960

6061
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
6162
});
62-
it('Check on regionId with countryId in address data.', function () {
63+
it('Check on regionId with countryId and regionId in address data.', function () {
6364
var result = newCustomerAddress({
64-
'country_id': 'US'
65+
'country_id': 'CA',
66+
region: {
67+
'region_id': 66
68+
}
6569
}),
6670
expected = {
67-
countryId: 'US',
68-
regionCode: null,
69-
region: null
71+
countryId: 'CA',
72+
regionId: 66
7073
};
7174

7275
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));

0 commit comments

Comments
 (0)