|
4 | 4 | /* eslint-disable func-names */ |
5 | 5 | /* eslint-disable max-params */ |
6 | 6 | const { _locale } = require('./_locale-infos.js') |
7 | | -const { _countries,_countriesrules, _cities, _addressPlaceholder } = require('./_countries.js') |
| 7 | +const { |
| 8 | + _countries, |
| 9 | + _countriesrules, |
| 10 | + _cities, |
| 11 | + _addressPlaceholder, |
| 12 | +} = require('./_countries.js') |
8 | 13 | const { getShipStateValue } = require('./_utils') |
9 | 14 |
|
10 | 15 | // temporaly workaorund |
@@ -448,14 +453,14 @@ class fnsCustomAddressForm { |
448 | 453 | // temporaly workaround for MLT |
449 | 454 | if (_country === 'MLT') { |
450 | 455 | _state = null |
451 | | - _postalCode = null |
452 | 456 | } |
453 | 457 | // end temporaly workaround for MLT |
454 | 458 |
|
455 | 459 | // temporaly workaround for USA and CAN |
456 | 460 | if ( |
457 | 461 | _country === 'USA' || |
458 | 462 | _country === 'ITA' || |
| 463 | + _country === 'MLT' || |
459 | 464 | _country === 'CAN' |
460 | 465 | ) { |
461 | 466 | _number = null |
@@ -1122,7 +1127,7 @@ class fnsCustomAddressForm { |
1122 | 1127 | .then(jsonRes => { |
1123 | 1128 | const { data: rules, success } = jsonRes |
1124 | 1129 |
|
1125 | | - if(country=="MLT") { |
| 1130 | + if (country == 'MLT') { |
1126 | 1131 | return _countriesrules.MLT |
1127 | 1132 | } |
1128 | 1133 |
|
@@ -1172,49 +1177,50 @@ class fnsCustomAddressForm { |
1172 | 1177 | $('.vcustom--vtex-omnishipping-1-x-address').length < 1 && |
1173 | 1178 | orderForm.items.length |
1174 | 1179 | ) { |
1175 | | - |
1176 | | - const lastCountry = _this.orderForm.shippingData?.address?.country || _this.orderForm.storePreferencesData.countryCode |
| 1180 | + const lastCountry = |
| 1181 | + (_this.orderForm.shippingData && |
| 1182 | + _this.orderForm.shippingData.address && |
| 1183 | + _this.orderForm.shippingData.address.country) || |
| 1184 | + _this.orderForm.storePreferencesData.countryCode |
1177 | 1185 |
|
1178 | 1186 | $('body').addClass(`${this.classOn}`) |
1179 | 1187 | _this.orderForm = orderForm |
1180 | | - _this |
1181 | | - .getCountryRule(lastCountry) |
1182 | | - .then(rules => { |
1183 | | - _this.addressrules = rules |
1184 | | - _this.bind() |
1185 | | - _this.deliveryCountries = window.checkout.deliveryCountries() |
1186 | | - _this.mainCountry = window.checkout.countryCode() |
1187 | | - _this.lang = _this.orderForm.clientPreferencesData.locale |
1188 | | - |
1189 | | - _this.locale = |
1190 | | - _locale[_this.orderForm.storePreferencesData.countryCode] || |
1191 | | - _locale.GBR |
1192 | | - |
1193 | | - if (_this.lang === 'es-AR') _this.lang = 'es' |
1194 | | - |
1195 | | - if (_this.orderForm && _this.orderForm.shippingData) { |
1196 | | - const shippingData = _this.orderForm.shippingData.address |
1197 | | - |
1198 | | - if (shippingData) { |
1199 | | - _this.updateAddress( |
1200 | | - shippingData.country, |
1201 | | - shippingData.postalCode, |
1202 | | - shippingData.city, |
1203 | | - shippingData.state, |
1204 | | - shippingData.street, |
1205 | | - shippingData.number, |
1206 | | - shippingData.complement, |
1207 | | - '', |
1208 | | - shippingData.addressId, |
1209 | | - shippingData.geoCoordinates |
1210 | | - ) |
1211 | | - } else { |
1212 | | - _this.updateAddress('') |
1213 | | - } |
| 1188 | + _this.getCountryRule(lastCountry).then(rules => { |
| 1189 | + _this.addressrules = rules |
| 1190 | + _this.bind() |
| 1191 | + _this.deliveryCountries = window.checkout.deliveryCountries() |
| 1192 | + _this.mainCountry = window.checkout.countryCode() |
| 1193 | + _this.lang = _this.orderForm.clientPreferencesData.locale |
| 1194 | + |
| 1195 | + _this.locale = |
| 1196 | + _locale[_this.orderForm.storePreferencesData.countryCode] || |
| 1197 | + _locale.GBR |
| 1198 | + |
| 1199 | + if (_this.lang === 'es-AR') _this.lang = 'es' |
| 1200 | + |
| 1201 | + if (_this.orderForm && _this.orderForm.shippingData) { |
| 1202 | + const shippingData = _this.orderForm.shippingData.address |
| 1203 | + |
| 1204 | + if (shippingData) { |
| 1205 | + _this.updateAddress( |
| 1206 | + shippingData.country, |
| 1207 | + shippingData.postalCode, |
| 1208 | + shippingData.city, |
| 1209 | + shippingData.state, |
| 1210 | + shippingData.street, |
| 1211 | + shippingData.number, |
| 1212 | + shippingData.complement, |
| 1213 | + '', |
| 1214 | + shippingData.addressId, |
| 1215 | + shippingData.geoCoordinates |
| 1216 | + ) |
| 1217 | + } else { |
| 1218 | + _this.updateAddress('') |
1214 | 1219 | } |
| 1220 | + } |
1215 | 1221 |
|
1216 | | - _this.form(orderForm) |
1217 | | - }) |
| 1222 | + _this.form(orderForm) |
| 1223 | + }) |
1218 | 1224 | } |
1219 | 1225 | } |
1220 | 1226 | } |
|
0 commit comments