Skip to content

Commit 62f4722

Browse files
committed
magento-engcom#43: refactor the addCustomer method so that it does not use the DataObject
- replace current usage, - keep BC by using the toArray method of the DataObject in the current public method
1 parent f148e35 commit 62f4722

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,13 @@ public function validateRow(array $rowData, $rowNumber)
308308
// Add new customer data into customer storage for address entity instance
309309
$websiteId = $this->_customerEntity->getWebsiteId($this->_currentWebsiteCode);
310310
if (!$this->_addressEntity->getCustomerStorage()->getCustomerId($this->_currentEmail, $websiteId)) {
311-
$customerData = new \Magento\Framework\DataObject(
311+
$this->_addressEntity->getCustomerStorage()->addCustomerByArray(
312312
[
313313
'id' => $this->_nextCustomerId,
314314
'email' => $this->_currentEmail,
315315
'website_id' => $websiteId,
316316
]
317317
);
318-
$this->_addressEntity->getCustomerStorage()->addCustomer($customerData);
319318
$this->_nextCustomerId++;
320319
}
321320

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,38 @@ public function load()
8181
$select->from($this->_customerCollection->getMainTable(), ['entity_id', 'website_id', 'email']);
8282
$results = $connection->fetchAll($select);
8383
foreach ($results as $customer) {
84-
$email = strtolower(trim($customer['email']));
85-
if (!isset($this->_customerIds[$email])) {
86-
$this->_customerIds[$email] = [];
87-
}
88-
$this->_customerIds[$email][$customer['website_id']] = $customer['entity_id'];
84+
$this->addCustomerByArray($customer);
8985
}
9086

9187
$this->_isCollectionLoaded = true;
9288
}
9389
}
9490

91+
/**
92+
* @param array $customer
93+
* @return $this
94+
*/
95+
public function addCustomerByArray(array $customer)
96+
{
97+
$email = strtolower(trim($customer['email']));
98+
if (!isset($this->_customerIds[$email])) {
99+
$this->_customerIds[$email] = [];
100+
}
101+
$this->_customerIds[$email][$customer['website_id']] = $customer['entity_id'];
102+
103+
return $this;
104+
}
105+
95106
/**
96107
* Add customer to array
97108
*
109+
* @deprecated @see addCustomerByArray
98110
* @param \Magento\Framework\DataObject|\Magento\Customer\Model\Customer $customer
99111
* @return $this
100112
*/
101113
public function addCustomer(\Magento\Framework\DataObject $customer)
102114
{
103-
$email = strtolower(trim($customer->getEmail()));
104-
if (!isset($this->_customerIds[$email])) {
105-
$this->_customerIds[$email] = [];
106-
}
107-
$this->_customerIds[$email][$customer->getWebsiteId()] = $customer->getId();
115+
$this->addCustomerByArray($customer->toArray());
108116

109117
return $this;
110118
}

0 commit comments

Comments
 (0)