Skip to content

Commit 82a08c3

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-83426: [Performance] Customer Import check data does not complete
1 parent 05ff9d5 commit 82a08c3

File tree

3 files changed

+75
-55
lines changed

3 files changed

+75
-55
lines changed

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -173,43 +173,6 @@ protected function _getCustomerId($email, $websiteCode)
173173
return false;
174174
}
175175

176-
/**
177-
* Pre-loading customers for existing customers checks in order
178-
* to perform mass validation/import efficiently.
179-
*
180-
* @param \Traversable $rows Each row must contain data from columns email
181-
* and website code.
182-
*
183-
* @return void
184-
*/
185-
public function prepareCustomerData(\Traversable $rows)
186-
{
187-
$customersPresent = [];
188-
foreach ($rows as $rowData) {
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-
}
199-
}
200-
$this->getCustomerStorage()->prepareCustomers($customersPresent);
201-
}
202-
203-
/**
204-
* @inheritDoc
205-
*/
206-
public function validateData()
207-
{
208-
$this->prepareCustomerData($this->getSource());
209-
210-
return parent::validateData();
211-
}
212-
213176
/**
214177
* Validate data row
215178
*

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -487,36 +487,56 @@ protected function _initAddresses()
487487
}
488488

489489
/**
490-
* @inheritDoc
491-
*
490+
* Pre-loading customers for existing customers checks in order
491+
* to perform mass validation/import efficiently.
492492
* Also loading existing addresses for requested customers.
493+
*
494+
* @param \Traversable $rows Each row must contain data from columns email
495+
* and website code.
496+
*
497+
* @return void
493498
*/
494499
public function prepareCustomerData(\Traversable $rows)
495500
{
496-
parent::prepareCustomerData($rows);
501+
$customersPresent = [];
502+
foreach ($rows as $rowData) {
503+
$email = isset($rowData[static::COLUMN_EMAIL])
504+
? $rowData[static::COLUMN_EMAIL] : null;
505+
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
506+
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
507+
if ($email && $websiteId !== false) {
508+
$customersPresent[] = [
509+
'email' => $email,
510+
'website_id' => $websiteId
511+
];
512+
}
513+
}
514+
$this->getCustomerStorage()->prepareCustomers($customersPresent);
497515

498516
$ids = [];
499-
foreach ($rows as $customerData) {
500-
if (isset($customerData[static::COLUMN_EMAIL])
501-
&& ($email = $customerData[static::COLUMN_EMAIL])
502-
&& isset($customerData[static::COLUMN_WEBSITE])
503-
&& (
504-
$websiteId = $this->getWebsiteId(
505-
$customerData[static::COLUMN_WEBSITE]
506-
)
507-
) !== false
508-
) {
509-
$id = $this->getCustomerStorage()
510-
->getCustomerId($email, $websiteId);
511-
if ($id) {
512-
$ids[] = $id;
513-
}
517+
foreach ($customersPresent as $customerData) {
518+
$id = $this->getCustomerStorage()->getCustomerId(
519+
$customerData['email'],
520+
$customerData['website_id']
521+
);
522+
if ($id) {
523+
$ids[] = $id;
514524
}
515525
}
516526

517527
$this->addressStorage->prepareAddresses($ids);
518528
}
519529

530+
/**
531+
* @inheritDoc
532+
*/
533+
public function validateData()
534+
{
535+
$this->prepareCustomerData($this->getSource());
536+
537+
return parent::validateData();
538+
}
539+
520540
/**
521541
* Initialize country regions hash for clever recognition
522542
*

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,43 @@ protected function _getNextEntityId()
323323
return $this->_nextEntityId++;
324324
}
325325

326+
/**
327+
* Pre-loading customers for existing customers checks in order
328+
* to perform mass validation/import efficiently.
329+
*
330+
* @param \Traversable $rows Each row must contain data from columns email
331+
* and website code.
332+
*
333+
* @return void
334+
*/
335+
public function prepareCustomerData(\Traversable $rows)
336+
{
337+
$customersPresent = [];
338+
foreach ($rows as $rowData) {
339+
$email = isset($rowData[static::COLUMN_EMAIL])
340+
? $rowData[static::COLUMN_EMAIL] : null;
341+
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
342+
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
343+
if ($email && $websiteId !== false) {
344+
$customersPresent[] = [
345+
'email' => $email,
346+
'website_id' => $websiteId
347+
];
348+
}
349+
}
350+
$this->getCustomerStorage()->prepareCustomers($customersPresent);
351+
}
352+
353+
/**
354+
* @inheritDoc
355+
*/
356+
public function validateData()
357+
{
358+
$this->prepareCustomerData($this->getSource());
359+
360+
return parent::validateData();
361+
}
362+
326363
/**
327364
* Prepare customer data for update
328365
*

0 commit comments

Comments
 (0)