File tree Expand file tree Collapse file tree 2 files changed +29
-18
lines changed
app/code/Magento/Checkout/view/frontend/web/js/model
dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/model Expand file tree Collapse file tree 2 files changed +29
-18
lines changed Original file line number Diff line number Diff line change @@ -17,18 +17,26 @@ define([
17
17
*/
18
18
return function ( addressData ) {
19
19
var identifier = Date . now ( ) ,
20
+ countryId ,
20
21
regionId ;
21
22
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 ;
26
34
}
27
35
28
36
return {
29
37
email : addressData . email ,
30
- countryId : addressData [ 'country_id' ] || addressData . countryId || window . checkoutConfig . defaultCountryId ,
31
- regionId : regionId || addressData . regionId ,
38
+ countryId : countryId ,
39
+ regionId : regionId ,
32
40
regionCode : addressData . region ? addressData . region [ 'region_code' ] : null ,
33
41
region : addressData . region ? addressData . region . region : null ,
34
42
customerId : addressData [ 'customer_id' ] || addressData . customerId ,
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ define([
14
14
beforeEach ( function ( ) {
15
15
16
16
window . checkoutConfig = {
17
- defaultCountryId : 'US'
17
+ defaultCountryId : 'US' ,
18
+ defaultRegionId : 1
18
19
} ;
19
20
20
21
newCustomerAddress = NewCustomerAddress ;
@@ -27,6 +28,7 @@ define([
27
28
it ( 'Check on empty object.' , function ( ) {
28
29
var expected = {
29
30
countryId : 'US' ,
31
+ regionId : 1 ,
30
32
regionCode : null ,
31
33
region : null
32
34
} ;
@@ -46,27 +48,28 @@ define([
46
48
expect ( result . canUseForBilling ( ) ) . toBeTruthy ( ) ;
47
49
} ) ;
48
50
49
- it ( 'Check on regionId with region object in address data.' , function ( ) {
51
+ it ( 'Check on regionId with country object in address data.' , function ( ) {
50
52
var result = newCustomerAddress ( {
51
- region : {
52
- 'region_id' : 1
53
- }
53
+ 'country_id' : 'CA'
54
54
} ) ,
55
55
expected = {
56
- countryId : 'US' ,
57
- regionId : 1
56
+ countryId : 'CA' ,
57
+ regionCode : null ,
58
+ region : null
58
59
} ;
59
60
60
61
expect ( JSON . stringify ( result ) ) . toEqual ( JSON . stringify ( expected ) ) ;
61
62
} ) ;
62
- it ( 'Check on regionId with countryId in address data.' , function ( ) {
63
+ it ( 'Check on regionId with countryId and regionId in address data.' , function ( ) {
63
64
var result = newCustomerAddress ( {
64
- 'country_id' : 'US'
65
+ 'country_id' : 'CA' ,
66
+ region : {
67
+ 'region_id' : 66
68
+ }
65
69
} ) ,
66
70
expected = {
67
- countryId : 'US' ,
68
- regionCode : null ,
69
- region : null
71
+ countryId : 'CA' ,
72
+ regionId : 66
70
73
} ;
71
74
72
75
expect ( JSON . stringify ( result ) ) . toEqual ( JSON . stringify ( expected ) ) ;
You can’t perform that action at this time.
0 commit comments