Skip to content

Commit e653591

Browse files
committed
magento-engcom/import-export-improvements#43: add a fallback for when older code with a customer object is used
- in the addCustomer covert $customerData['id'] to $customerData['entity_id'] so that older code that uses customer objects will still work as expected
1 parent d45ade0 commit e653591

File tree

2 files changed

+19
-1
lines changed
  • app/code/Magento/CustomerImportExport

2 files changed

+19
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ public function addCustomerByArray(array $customer)
112112
*/
113113
public function addCustomer(\Magento\Framework\DataObject $customer)
114114
{
115-
$this->addCustomerByArray($customer->toArray());
115+
$customerData = $customer->toArray();
116+
if (!isset($customerData['entity_id']) && isset($customer['id'])) {
117+
$customerData['entity_id'] = $customerData['id'];
118+
}
119+
$this->addCustomerByArray($customerData);
116120

117121
return $this;
118122
}

app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/Customer/StorageTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ public function testLoad()
101101
}
102102

103103
public function testAddCustomer()
104+
{
105+
$customer = new \Magento\Framework\DataObject(['id' => 1, 'website_id' => 1, 'email' => '[email protected]']);
106+
$this->_model->addCustomer($customer);
107+
108+
$propertyName = '_customerIds';
109+
$this->assertAttributeCount(1, $propertyName, $this->_model);
110+
$this->assertAttributeContains([$customer->getWebsiteId() => $customer->getId()], $propertyName, $this->_model);
111+
$this->assertEquals(
112+
$customer->getId(),
113+
$this->_model->getCustomerId($customer->getEmail(), $customer->getWebsiteId())
114+
);
115+
}
116+
117+
public function testAddCustomerByArray()
104118
{
105119
$propertyName = '_customerIds';
106120
$customer = $this->_addCustomerToStorage();

0 commit comments

Comments
 (0)