@@ -54,6 +54,8 @@ class Address extends AbstractCustomer
54
54
55
55
/**#@-*/
56
56
57
+ const COLUMN_REGION_ID = 'region_id ' ;
58
+
57
59
/**#@+
58
60
* Particular columns that contains of customer default addresses
59
61
*/
@@ -666,13 +668,17 @@ protected function _prepareDataForUpdate(array $rowData): array
666
668
}
667
669
}
668
670
// let's try to find region ID
669
- $ entityRow [' region_id ' ] = null ;
671
+ $ entityRow [self :: COLUMN_REGION_ID ] = null ;
670
672
671
- if (!empty ($ rowData [self ::COLUMN_REGION ])
672
- && $ this ->getCountryRegionId ($ rowData [self ::COLUMN_COUNTRY_ID ], $ rowData [self ::COLUMN_REGION ]) !== false ) {
673
- $ regionId = $ this ->getCountryRegionId ($ rowData [self ::COLUMN_COUNTRY_ID ], $ rowData [self ::COLUMN_REGION ]);
674
- $ entityRow [self ::COLUMN_REGION ] = $ this ->_regions [$ regionId ];
675
- $ entityRow ['region_id ' ] = $ regionId ;
673
+ if (!empty ($ entityRow [self ::COLUMN_REGION ]) && !empty ($ entityRow [self ::COLUMN_COUNTRY_ID ])) {
674
+ $ entityRow [self ::COLUMN_REGION_ID ] = $ this ->getCountryRegionId (
675
+ $ entityRow [self ::COLUMN_COUNTRY_ID ],
676
+ $ entityRow [self ::COLUMN_REGION ]
677
+ );
678
+ // override the region name with its proper name if region ID is found
679
+ $ entityRow [self ::COLUMN_REGION ] = $ entityRow [self ::COLUMN_REGION_ID ] !== null
680
+ ? $ this ->_regions [$ entityRow [self ::COLUMN_REGION_ID ]]
681
+ : $ entityRow [self ::COLUMN_REGION ];
676
682
}
677
683
if ($ newAddress ) {
678
684
$ entityRowNew = $ entityRow ;
@@ -833,7 +839,7 @@ public static function getDefaultAddressAttributeMapping()
833
839
* Check if address for import is empty (for customer composite mode)
834
840
*
835
841
* @param array $rowData
836
- * @return array
842
+ * @return bool
837
843
*/
838
844
protected function _isOptionalAddressEmpty (array $ rowData )
839
845
{
@@ -914,7 +920,8 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
914
920
915
921
if (isset ($ rowData [self ::COLUMN_REGION ])
916
922
&& !empty ($ rowData [self ::COLUMN_REGION ])
917
- && false === $ this ->getCountryRegionId (
923
+ && count ($ this ->getCountryRegions ($ rowData [self ::COLUMN_COUNTRY_ID ])) > 0
924
+ && null === $ this ->getCountryRegionId (
918
925
$ rowData [self ::COLUMN_COUNTRY_ID ],
919
926
$ rowData [self ::COLUMN_REGION ]
920
927
)
@@ -994,18 +1001,22 @@ public function setCustomerAttributes($customerAttributes)
994
1001
*
995
1002
* @param string $countryId
996
1003
* @param string $region
997
- * @return bool| int
1004
+ * @return int|null
998
1005
*/
999
- private function getCountryRegionId (string $ countryId , string $ region )
1006
+ private function getCountryRegionId (string $ countryId , string $ region ): ? int
1000
1007
{
1001
- $ countryNormalized = strtolower ($ countryId );
1002
- $ regionNormalized = strtolower ($ region );
1003
-
1004
- if (isset ($ this ->_countryRegions [$ countryNormalized ])
1005
- && isset ($ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ])) {
1006
- return $ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ];
1007
- }
1008
+ $ countryRegions = $ this ->getCountryRegions ($ countryId );
1009
+ return $ countryRegions [strtolower ($ region )] ?? null ;
1010
+ }
1008
1011
1009
- return false ;
1012
+ /**
1013
+ * Get country regions
1014
+ *
1015
+ * @param string $countryId
1016
+ * @return array
1017
+ */
1018
+ private function getCountryRegions (string $ countryId ): array
1019
+ {
1020
+ return $ this ->_countryRegions [strtolower ($ countryId )] ?? [];
1010
1021
}
1011
1022
}
0 commit comments