Skip to content

Commit 38fc6a1

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-28011' of https://github.corp.ebay.com/magento-firedrakes/magento2ce into MAGETWO-28011
2 parents 5083f13 + ebf37f1 commit 38fc6a1

File tree

3 files changed

+47
-51
lines changed

3 files changed

+47
-51
lines changed

app/code/Magento/Customer/Model/Resource/Customer.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,15 @@ protected function _saveAddresses(\Magento\Customer\Model\Customer $customer)
202202
}
203203
}
204204
}
205-
//@TODO: find appropriate place
206205
$changedAddresses = [];
207-
if ($defaultBillingId != $customer->getData('default_billing')) {
208-
$changedAddresses['default_billing'] = $customer->getData('default_billing');
209-
}
210-
if ($defaultShippingId != $customer->getData('default_shipping')) {
211-
$changedAddresses['default_shipping'] = $customer->getData('default_shipping');
212-
}
213-
if ($changedAddresses) {
214-
$this->_getWriteAdapter()->update(
215-
$this->getTable('customer_entity'),
216-
$changedAddresses,
217-
$this->_getWriteAdapter()->quoteInto('entity_id = ?', $customer->getId())
218-
);
219-
}
206+
207+
$changedAddresses['default_billing'] = $customer->getData('default_billing');
208+
$changedAddresses['default_shipping'] = $customer->getData('default_shipping');
209+
$this->_getWriteAdapter()->update(
210+
$this->getTable('customer_entity'),
211+
$changedAddresses,
212+
$this->_getWriteAdapter()->quoteInto('entity_id = ?', $customer->getId())
213+
);
220214

221215
return $this;
222216
}

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ protected function _prepareDataForUpdate(array $rowData)
517517
foreach (self::getDefaultAddressAttributeMapping() as $columnName => $attributeCode) {
518518
if (!empty($rowData[$columnName])) {
519519
/** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
520-
$attribute = $this->_getCustomerEntity()->getAttribute($attributeCode);
521-
$defaults[$attribute->getBackend()->getTable()][$customerId][$attribute->getId()] = $addressId;
520+
$table = $this->_getCustomerEntity()->getResource()->getTable('customer_entity');
521+
$defaults[$table][$customerId][$attributeCode] = $addressId;
522522
}
523523
}
524524

@@ -586,21 +586,15 @@ protected function _saveAddressAttributes(array $attributesData)
586586
*/
587587
protected function _saveCustomerDefaults(array $defaults)
588588
{
589-
/** @var $entity \Magento\Customer\Model\Customer */
590-
$entity = $this->_customerFactory->create();
591-
592589
foreach ($defaults as $tableName => $data) {
593-
$tableData = [];
594-
foreach ($data as $customerId => $attributeData) {
595-
foreach ($attributeData as $attributeId => $value) {
596-
$tableData[] = [
597-
'entity_id' => $customerId,
598-
'attribute_id' => $attributeId,
599-
'value' => $value,
600-
];
601-
}
590+
foreach ($data as $customerId => $defaultsData) {
591+
$data = array_merge(
592+
['entity_id' => $customerId],
593+
$defaultsData
594+
);
595+
$this->_connection->insertOnDuplicate($tableName, $data, array_keys($defaultsData));
602596
}
603-
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
597+
604598
}
605599
return $this;
606600
}

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -298,33 +298,36 @@ protected function _prepareDataForUpdate(array $rowData)
298298
} else {
299299
$createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
300300
}
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+
301312
$entityRow = [
302313
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
303314
'store_id' => empty($rowData[self::COLUMN_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COLUMN_STORE]],
304315
'created_at' => $createdAt->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
305316
'updated_at' => $now->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
317+
'entity_id' => $entityId,
306318
];
307319

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']);
323323
}
324324

325325
// attribute values
326326
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']) {
328331
/** @var $attribute \Magento\Customer\Model\Attribute */
329332
$attribute = $this->_customerModel->getAttribute($attributeCode);
330333
$backendModel = $attribute->getBackendModel();
@@ -344,15 +347,20 @@ protected function _prepareDataForUpdate(array $rowData)
344347

345348
// restore 'backend_model' to avoid default setting
346349
$attribute->setBackendModel($backendModel);
350+
} else {
351+
$entityRow[$attributeCode] = $value;
347352
}
348353
}
349354

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;
356364
}
357365

358366
return [

0 commit comments

Comments
 (0)