Skip to content

Commit fca38f6

Browse files
AnujnehraAnujnehra
authored andcommitted
ACP2E-2301: Customers and Addresses (single file) Import fails
1 parent 901477a commit fca38f6

File tree

6 files changed

+10
-117
lines changed

6 files changed

+10
-117
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,6 @@ protected function _importData()
534534
$deleteRowIds = [];
535535

536536
foreach ($bunch as $rowNumber => $rowData) {
537-
if (!isset($rowData['_website'])) {
538-
continue;
539-
}
540537
// check row data
541538
if ($this->_isOptionalAddressEmpty($rowData) || !$this->validateRow($rowData, $rowNumber)) {
542539
continue;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,6 @@ protected function _importData()
519519
$attributesToSave = [];
520520

521521
foreach ($bunch as $rowNumber => $rowData) {
522-
if (!isset($rowData['_website'])) {
523-
continue;
524-
}
525522
if (!$this->validateRow($rowData, $rowNumber)) {
526523
continue;
527524
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ protected function _initAddressAttributes()
278278
*/
279279
protected function _importData()
280280
{
281+
if ($this->getIds()) {
282+
$this->_customerEntity->setIds($this->getIds());
283+
$this->_addressEntity->setCustomerAttributes($this->_customerAttributes)->setIds($this->getIds());
284+
}
281285
$result = $this->_customerEntity->importData();
282286
$this->countItemsCreated += $this->_customerEntity->getCreatedItemsCount();
283287
$this->countItemsUpdated += $this->_customerEntity->getUpdatedItemsCount();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public function getNextUniqueBunch($ids = null)
8080
protected function _prepareRow(array $rowData)
8181
{
8282
$entityCustomer = CustomerComposite::COMPONENT_ENTITY_CUSTOMER;
83-
if ((isset($rowData['_scope'])) && $this->_entityType == $entityCustomer) {
84-
if ($rowData['_scope'] == CustomerComposite::SCOPE_DEFAULT) {
83+
if ($this->_entityType == $entityCustomer) {
84+
if ((isset($rowData['_scope'])) && $rowData['_scope'] == CustomerComposite::SCOPE_DEFAULT) {
8585
return $rowData;
8686
} else {
8787
return null;

app/code/Magento/CustomerImportExport/Test/Unit/Model/Import/AddressTest.php

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use Magento\Store\Model\StoreManager;
4242
use PHPUnit\Framework\MockObject\MockObject;
4343
use PHPUnit\Framework\TestCase;
44-
use ReflectionException;
4544

4645
/**
4746
* Tests Magento\CustomerImportExport\Model\Import\Address.
@@ -150,16 +149,6 @@ class AddressTest extends TestCase
150149
*/
151150
private $countryWithWebsites;
152151

153-
/**
154-
* @var \stdClass|MockObject
155-
*/
156-
private $dataSourceModel;
157-
158-
/**
159-
* @var \stdClass|MockObject
160-
*/
161-
private $connection;
162-
163152
/**
164153
* Init entity adapter model
165154
*/
@@ -204,14 +193,10 @@ protected function tearDown(): void
204193
*/
205194
protected function _getModelDependencies()
206195
{
207-
$this->dataSourceModel = $this->getMockBuilder(\stdClass::class)
208-
->addMethods(['getNextBunch', 'getNextUniqueBunch', 'getIterator', 'rewind'])
209-
->disableOriginalConstructor()
210-
->getMock();
211-
$this->connection = $this->getMockBuilder(\stdClass::class)
212-
->addMethods(['insertMultiple'])
196+
$dataSourceModel = $this->getMockBuilder(\stdClass::class)->addMethods(['getNextBunch'])
213197
->disableOriginalConstructor()
214198
->getMock();
199+
$connection = $this->createMock(\stdClass::class);
215200
$attributeCollection = $this->_createAttrCollectionMock();
216201
$customerStorage = $this->_createCustomerStorageMock();
217202
$customerEntity = $this->_createCustomerEntityMock();
@@ -230,8 +215,8 @@ protected function _getModelDependencies()
230215
}
231216

232217
$data = [
233-
'data_source_model' => $this->dataSourceModel,
234-
'connection' => $this->connection,
218+
'data_source_model' => $dataSourceModel,
219+
'connection' => $connection,
235220
'page_size' => 1,
236221
'max_data_size' => 1,
237222
'bunch_size' => 1,
@@ -586,63 +571,4 @@ public function validateDeleteAddressEntities(array $deleteRowIds)
586571
$this->assertContains($this->_customBehaviour['delete_id'], $deleteRowIds);
587572
return $this->_model;
588573
}
589-
590-
/**
591-
* @return void
592-
* @throws ReflectionException
593-
*/
594-
public function testImportData(): void
595-
{
596-
$this->dataSourceModel->expects($this->any())
597-
->method('getNextUniqueBunch')
598-
->willReturnOnConsecutiveCalls(
599-
['_email' => 'jondoe@example.com'],
600-
['_website' => 'base'],
601-
['_store'=> 'admin'],
602-
['_entity_id' => 'abc'],
603-
null,
604-
['_email' => 'jondoe@example.com'],
605-
['_store' => 'admin'],
606-
['_entity_id' => 'abc']
607-
);
608-
$this->dataSourceModel->method('getIterator')->willReturnSelf();
609-
$this->setProtectedProperty($this->_model, '_websiteCodeToId', [
610-
'base' => 1,
611-
]);
612-
$method = $this->setMethodAccessible('_importData');
613-
$this->connection->method('insertMultiple')->willReturnSelf();
614-
$result = $method->invokeArgs($this->_model, []);
615-
$this->assertTrue($result);
616-
}
617-
618-
/**
619-
* Invoke any method of class.
620-
*
621-
* @param string $method
622-
*
623-
* @return mixed
624-
* @throws ReflectionException
625-
*/
626-
private function setMethodAccessible(string $method): mixed
627-
{
628-
$class = new \ReflectionClass(Address::class);
629-
return $class->getMethod($method);
630-
}
631-
632-
/**
633-
* Sets a protected property on a given object via reflection
634-
*
635-
* @param $object - instance in which protected value is being modified
636-
* @param $property - property on instance being modified
637-
* @param $value - new value of the property being modified
638-
*
639-
* @return void
640-
* @throws ReflectionException
641-
*/
642-
private function setProtectedProperty($object, $property, $value): void
643-
{
644-
$reflection = new \ReflectionClass($object);
645-
$reflection_property = $reflection->getProperty($property);
646-
$reflection_property->setValue($object, $value);
647-
}
648574
}

app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/CustomerComposite/DataTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -218,37 +218,6 @@ public function getNextBunchDataProvider()
218218
]
219219
),
220220
'$expectedData' => [],
221-
],
222-
'customer entity default no _scope' => [
223-
'$entityType' => CustomerComposite::COMPONENT_ENTITY_CUSTOMER,
224-
'$bunchData' => json_encode(
225-
[
226-
[
227-
Address::COLUMN_WEBSITE => 'website1',
228-
Address::COLUMN_EMAIL => 'email1',
229-
Address::COLUMN_ADDRESS_ID => null,
230-
CustomerComposite::COLUMN_DEFAULT_BILLING => 'value',
231-
CustomerComposite::COLUMN_DEFAULT_SHIPPING => 'value',
232-
'customer_attribute1' => 'value',
233-
'customer_attribute2' => 'value',
234-
CustomerComposite::COLUMN_ADDRESS_PREFIX . 'attribute1' => 'value',
235-
CustomerComposite::COLUMN_ADDRESS_PREFIX . 'attribute2' => 'value',
236-
],
237-
]
238-
),
239-
'$expectedData' => [
240-
0 => [
241-
Address::COLUMN_WEBSITE => 'website1',
242-
Address::COLUMN_EMAIL => 'email1',
243-
Address::COLUMN_ADDRESS_ID => null,
244-
CustomerComposite::COLUMN_DEFAULT_BILLING => 'value',
245-
CustomerComposite::COLUMN_DEFAULT_SHIPPING => 'value',
246-
'customer_attribute1' => 'value',
247-
'customer_attribute2' => 'value',
248-
'attribute1' => 'value',
249-
'attribute2' => 'value',
250-
],
251-
],
252221
]
253222
];
254223
}

0 commit comments

Comments
 (0)