Skip to content

Commit 0917293

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-83426: [Performance] Customer Import check data does not complete
1 parent 97c367f commit 0917293

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,16 @@ public function prepareCustomerData(\Traversable $rows)
186186
{
187187
$customersPresent = [];
188188
foreach ($rows as $rowData) {
189-
$customersPresent[] = [
190-
'email' => $rowData[static::COLUMN_EMAIL],
191-
'website_id' => $this->getWebsiteId(
192-
$rowData[static::COLUMN_WEBSITE]
193-
)
194-
];
189+
$email = isset($rowData[static::COLUMN_EMAIL])
190+
? $rowData[static::COLUMN_EMAIL] : null;
191+
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
192+
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
193+
if ($email && $websiteId !== false) {
194+
$customersPresent[] = [
195+
'email' => $email,
196+
'website_id' => $websiteId
197+
];
198+
}
195199
}
196200
$this->getCustomerStorage()->prepareCustomers($customersPresent);
197201
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,17 @@ public function prepareCustomerData(\Traversable $rows)
484484
parent::prepareCustomerData($rows);
485485
$ids = [];
486486
foreach ($rows as $customerData) {
487-
$id = $this->getCustomerStorage()
488-
->getCustomerId(
489-
$customerData[static::COLUMN_EMAIL],
490-
$this->getWebsiteId($customerData[static::COLUMN_WEBSITE])
491-
);
492-
if ($id) {
493-
$ids[] = $id;
487+
$email = isset($customerData[static::COLUMN_EMAIL])
488+
? $customerData[static::COLUMN_EMAIL] : null;
489+
$websiteId = isset($customerData[static::COLUMN_WEBSITE])
490+
? $this->getWebsiteId($customerData[static::COLUMN_WEBSITE])
491+
: false;
492+
if ($email && $websiteId !== false) {
493+
$id = $this->getCustomerStorage()
494+
->getCustomerId($email, $websiteId);
495+
if ($id) {
496+
$ids[] = $id;
497+
}
494498
}
495499
}
496500

@@ -955,7 +959,9 @@ protected function _validateRowForDelete(array $rowData, $rowNumber)
955959
} else {
956960
if (!strlen($addressId)) {
957961
$this->addRowError(self::ERROR_ADDRESS_ID_IS_EMPTY, $rowNumber);
958-
} elseif (!in_array($addressId, $this->_addresses[$customerId])) {
962+
} elseif (!in_array($customerId, $this->_addresses)
963+
|| !in_array($addressId, $this->_addresses[$customerId])
964+
) {
959965
$this->addRowError(self::ERROR_ADDRESS_NOT_FOUND, $rowNumber);
960966
}
961967
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ function ($email, $websiteId) {
272272
return false;
273273
}
274274
);
275+
$customerStorage->expects($this->any())->method('prepareCustomers');
275276

276277
return $customerStorage;
277278
}
@@ -366,7 +367,9 @@ protected function _getModelMockForTestImportDataWithCustomBehaviour()
366367
'_saveCustomerDefaults',
367368
'_deleteAddressEntities',
368369
'_mergeEntityAttributes',
369-
'getErrorAggregator'
370+
'getErrorAggregator',
371+
'getCustomerStorage',
372+
'prepareCustomerData'
370373
],
371374
[],
372375
'',
@@ -382,13 +385,16 @@ protected function _getModelMockForTestImportDataWithCustomBehaviour()
382385
// mock to imitate data source model
383386
$dataSourceMock = $this->getMock(
384387
'Magento\ImportExport\Model\ResourceModel\Import\Data',
385-
['getNextBunch', '__wakeup'],
388+
['getNextBunch', '__wakeup', 'getIterator'],
386389
[],
387390
'',
388391
false
389392
);
390393
$dataSourceMock->expects($this->at(0))->method('getNextBunch')->will($this->returnValue($customBehaviorRows));
391394
$dataSourceMock->expects($this->at(1))->method('getNextBunch')->will($this->returnValue(null));
395+
$dataSourceMock->expects($this->any())
396+
->method('getIterator')
397+
->willReturn($this->getMockForAbstractClass(\Iterator::class));
392398

393399
$dataSourceModel = new \ReflectionProperty(
394400
'Magento\CustomerImportExport\Model\Import\Address',
@@ -426,7 +432,9 @@ protected function _getModelMockForTestImportDataWithCustomBehaviour()
426432
);
427433

428434
$modelMock->expects($this->any())->method('_mergeEntityAttributes')->will($this->returnValue([]));
429-
435+
$modelMock->expects($this->any())
436+
->method('getCustomerStorage')
437+
->willReturn($this->_createCustomerStorageMock());
430438
return $modelMock;
431439
}
432440

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Magento\CustomerImportExport\Test\Unit\Model\Import;
1313

1414
use Magento\CustomerImportExport\Model\Import\Customer;
15+
use Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage;
1516

1617
class CustomerTest extends \PHPUnit_Framework_TestCase
1718
{
@@ -92,6 +93,7 @@ protected function _getModelMockForTestImportDataWithCustomBehaviour()
9293
'_saveCustomerAttributes',
9394
'_deleteCustomerEntities',
9495
'getErrorAggregator',
96+
'getCustomerStorage'
9597
])
9698
->getMock();
9799

@@ -157,6 +159,14 @@ protected function _getModelMockForTestImportDataWithCustomBehaviour()
157159
$modelMock->expects($this->any())
158160
->method('getErrorAggregator')
159161
->will($this->returnValue($errorAggregator));
162+
/** @var \PHPUnit_Framework_MockObject_MockObject $storageMock */
163+
$storageMock = $this->getMockBuilder(Storage::class)
164+
->disableOriginalConstructor()
165+
->getMock();
166+
$storageMock->expects($this->any())->method('prepareCustomers');
167+
$modelMock->expects($this->any())
168+
->method('getCustomerStorage')
169+
->willReturn($storageMock);
160170

161171
return $modelMock;
162172
}

0 commit comments

Comments
 (0)