@@ -298,33 +298,36 @@ protected function _prepareDataForUpdate(array $rowData)
298
298
} else {
299
299
$ createdAt = (new \DateTime ())->setTimestamp (strtotime ($ rowData ['created_at ' ]));
300
300
}
301
+
302
+ $ emailInLowercase = strtolower ($ rowData [self ::COLUMN_EMAIL ]);
303
+ $ newCustomer = false ;
304
+ $ entityId = $ this ->_getCustomerId ($ emailInLowercase , $ rowData [self ::COLUMN_WEBSITE ]);
305
+ if (!$ entityId ) {
306
+ // create
307
+ $ newCustomer = true ;
308
+ $ entityId = $ this ->_getNextEntityId ();
309
+ $ this ->_newCustomers [$ emailInLowercase ][$ rowData [self ::COLUMN_WEBSITE ]] = $ entityId ;
310
+ }
311
+
301
312
$ entityRow = [
302
313
'group_id ' => empty ($ rowData ['group_id ' ]) ? self ::DEFAULT_GROUP_ID : $ rowData ['group_id ' ],
303
314
'store_id ' => empty ($ rowData [self ::COLUMN_STORE ]) ? 0 : $ this ->_storeCodeToId [$ rowData [self ::COLUMN_STORE ]],
304
315
'created_at ' => $ createdAt ->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT ),
305
316
'updated_at ' => $ now ->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT ),
317
+ 'entity_id ' => $ entityId ,
306
318
];
307
319
308
- $ emailInLowercase = strtolower ($ rowData [self ::COLUMN_EMAIL ]);
309
- if ($ entityId = $ this ->_getCustomerId ($ emailInLowercase , $ rowData [self ::COLUMN_WEBSITE ])) {
310
- // edit
311
- $ entityRow ['entity_id ' ] = $ entityId ;
312
- $ entitiesToUpdate [] = $ entityRow ;
313
- } else {
314
- // create
315
- $ entityId = $ this ->_getNextEntityId ();
316
- $ entityRow ['entity_id ' ] = $ entityId ;
317
- $ entityRow ['website_id ' ] = $ this ->_websiteCodeToId [$ rowData [self ::COLUMN_WEBSITE ]];
318
- $ entityRow ['email ' ] = $ emailInLowercase ;
319
- $ entityRow ['is_active ' ] = 1 ;
320
- $ entitiesToCreate [] = $ entityRow ;
321
-
322
- $ this ->_newCustomers [$ emailInLowercase ][$ rowData [self ::COLUMN_WEBSITE ]] = $ entityId ;
320
+ // password change/set
321
+ if (isset ($ rowData ['password ' ]) && strlen ($ rowData ['password ' ])) {
322
+ $ entityRow ['password_hash ' ] = $ this ->_customerModel ->hashPassword ($ rowData ['password ' ]);
323
323
}
324
324
325
325
// attribute values
326
326
foreach (array_intersect_key ($ rowData , $ this ->_attributes ) as $ attributeCode => $ value ) {
327
- if (!$ this ->_attributes [$ attributeCode ]['is_static ' ] && strlen ($ value )) {
327
+ if ($ newCustomer && !strlen ($ value )) {
328
+ continue ;
329
+ }
330
+ if (!$ this ->_attributes [$ attributeCode ]['is_static ' ]) {
328
331
/** @var $attribute \Magento\Customer\Model\Attribute */
329
332
$ attribute = $ this ->_customerModel ->getAttribute ($ attributeCode );
330
333
$ backendModel = $ attribute ->getBackendModel ();
@@ -344,15 +347,20 @@ protected function _prepareDataForUpdate(array $rowData)
344
347
345
348
// restore 'backend_model' to avoid default setting
346
349
$ attribute ->setBackendModel ($ backendModel );
350
+ } else {
351
+ $ entityRow [$ attributeCode ] = $ value ;
347
352
}
348
353
}
349
354
350
- // password change/set
351
- if (isset ($ rowData ['password ' ]) && strlen ($ rowData ['password ' ])) {
352
- $ attributesToSave [$ passwordStorageTable ][$ entityId ][$ passwordAttributeId ] = $ this ->_customerModel
353
- ->hashPassword (
354
- $ rowData ['password ' ]
355
- );
355
+ if ($ newCustomer ) {
356
+ // create
357
+ $ entityRow ['website_id ' ] = $ this ->_websiteCodeToId [$ rowData [self ::COLUMN_WEBSITE ]];
358
+ $ entityRow ['email ' ] = $ emailInLowercase ;
359
+ $ entityRow ['is_active ' ] = 1 ;
360
+ $ entitiesToCreate [] = $ entityRow ;
361
+ } else {
362
+ // edit
363
+ $ entitiesToUpdate [] = $ entityRow ;
356
364
}
357
365
358
366
return [
0 commit comments