6
6
namespace Magento \CustomerImportExport \Model \Import ;
7
7
8
8
use Magento \Customer \Model \ResourceModel \Address \Attribute \Source as Sources ;
9
+ use Magento \Framework \Stdlib \DateTime ;
9
10
use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingErrorAggregatorInterface ;
10
11
use Magento \Framework \App \ObjectManager ;
11
12
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
@@ -218,7 +219,7 @@ class Address extends AbstractCustomer
218
219
protected $ _addressFactory ;
219
220
220
221
/**
221
- * @var \Magento\Framework\Stdlib\ DateTime
222
+ * @var DateTime
222
223
*/
223
224
protected $ dateTime ;
224
225
@@ -271,7 +272,7 @@ class Address extends AbstractCustomer
271
272
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
272
273
* @param \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory
273
274
* @param \Magento\Customer\Model\ResourceModel\Address\Attribute\CollectionFactory $attributesFactory
274
- * @param \Magento\Framework\Stdlib\ DateTime $dateTime
275
+ * @param DateTime $dateTime
275
276
* @param \Magento\Customer\Model\Address\Validator\Postcode $postcodeValidator
276
277
* @param array $data
277
278
* @param Sources\CountryWithWebsites|null $countryWithWebsites
@@ -295,7 +296,7 @@ public function __construct(
295
296
\Magento \Customer \Model \CustomerFactory $ customerFactory ,
296
297
\Magento \Customer \Model \ResourceModel \Address \CollectionFactory $ addressColFactory ,
297
298
\Magento \Customer \Model \ResourceModel \Address \Attribute \CollectionFactory $ attributesFactory ,
298
- \ Magento \ Framework \ Stdlib \ DateTime $ dateTime ,
299
+ DateTime $ dateTime ,
299
300
\Magento \Customer \Model \Address \Validator \Postcode $ postcodeValidator ,
300
301
array $ data = [],
301
302
Sources \CountryWithWebsites $ countryWithWebsites = null
@@ -587,12 +588,8 @@ protected function _prepareDataForUpdate(array $rowData)
587
588
$ defaults = [];
588
589
$ newAddress = true ;
589
590
// get address id
590
- if (isset (
591
- $ this ->_addresses [$ customerId ]
592
- ) && in_array (
593
- $ rowData [self ::COLUMN_ADDRESS_ID ],
594
- $ this ->_addresses [$ customerId ]
595
- )
591
+ if (isset ($ this ->_addresses [$ customerId ])
592
+ && in_array ($ rowData [self ::COLUMN_ADDRESS_ID ], $ this ->_addresses [$ customerId ])
596
593
) {
597
594
$ newAddress = false ;
598
595
$ addressId = $ rowData [self ::COLUMN_ADDRESS_ID ];
@@ -602,7 +599,7 @@ protected function _prepareDataForUpdate(array $rowData)
602
599
$ entityRow = [
603
600
'entity_id ' => $ addressId ,
604
601
'parent_id ' => $ customerId ,
605
- 'updated_at ' => (new \DateTime ())->format (\ Magento \ Framework \ Stdlib \ DateTime::DATETIME_PHP_FORMAT ),
602
+ 'updated_at ' => (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT ),
606
603
];
607
604
$ websiteId = $ this ->_websiteCodeToId [$ rowData [self ::COLUMN_WEBSITE ]];
608
605
@@ -625,7 +622,7 @@ protected function _prepareDataForUpdate(array $rowData)
625
622
$ value = $ attributeParams ['options ' ][strtolower ($ rowData [$ attributeAlias ])];
626
623
} elseif ('datetime ' == $ attributeParams ['type ' ]) {
627
624
$ value = (new \DateTime ())->setTimestamp (strtotime ($ rowData [$ attributeAlias ]));
628
- $ value = $ value ->format (\ Magento \ Framework \ Stdlib \ DateTime::DATETIME_PHP_FORMAT );
625
+ $ value = $ value ->format (DateTime::DATETIME_PHP_FORMAT );
629
626
} elseif ('multiselect ' == $ attributeParams ['type ' ]) {
630
627
$ separator = isset ($ this ->_parameters [Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR ]) ?
631
628
$ this ->_parameters [Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR ] :
@@ -655,22 +652,11 @@ protected function _prepareDataForUpdate(array $rowData)
655
652
}
656
653
657
654
// let's try to find region ID
658
- $ entityRow ['region_id ' ] = null ;
659
- if (!empty ($ rowData [self ::COLUMN_REGION ])) {
660
- $ countryNormalized = strtolower ($ rowData [self ::COLUMN_COUNTRY_ID ]);
661
- $ regionNormalized = strtolower ($ rowData [self ::COLUMN_REGION ]);
662
-
663
- if (isset ($ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ])) {
664
- $ regionId = $ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ];
665
- $ entityRow [self ::COLUMN_REGION ] = $ this ->_regions [$ regionId ];
666
- $ entityRow ['region_id ' ] = $ regionId ;
667
- }
668
- }
655
+ $ entityRow = $ this ->fillRegionData ($ rowData , $ entityRow );
669
656
670
657
if ($ newAddress ) {
671
658
$ entityRowNew = $ entityRow ;
672
- $ entityRowNew ['created_at ' ] =
673
- (new \DateTime ())->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT );
659
+ $ entityRowNew ['created_at ' ] = (new \DateTime ())->format (DateTime::DATETIME_PHP_FORMAT );
674
660
} else {
675
661
$ entityRowUpdate = $ entityRow ;
676
662
}
@@ -959,4 +945,28 @@ public function setCustomerAttributes($customerAttributes)
959
945
$ this ->_customerAttributes = $ customerAttributes ;
960
946
return $ this ;
961
947
}
948
+
949
+ /**
950
+ * Try to get region_id and set it to $entityRow.
951
+ *
952
+ * @param array $rowData
953
+ * @param array $entityRow
954
+ * @return array
955
+ */
956
+ private function fillRegionData (array $ rowData , array $ entityRow )
957
+ {
958
+ $ entityRow ['region_id ' ] = null ;
959
+ if (!empty ($ rowData [self ::COLUMN_REGION ])) {
960
+ $ countryNormalized = strtolower ($ rowData [self ::COLUMN_COUNTRY_ID ]);
961
+ $ regionNormalized = strtolower ($ rowData [self ::COLUMN_REGION ]);
962
+
963
+ if (isset ($ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ])) {
964
+ $ regionId = $ this ->_countryRegions [$ countryNormalized ][$ regionNormalized ];
965
+ $ entityRow [self ::COLUMN_REGION ] = $ this ->_regions [$ regionId ];
966
+ $ entityRow ['region_id ' ] = $ regionId ;
967
+ }
968
+ }
969
+
970
+ return $ entityRow ;
971
+ }
962
972
}
0 commit comments