Skip to content

Commit 6353de6

Browse files
committed
ACP2E-3165: [Cloud] Getting error while checking the data in import data using CSV
- Fixed the CR comments.
1 parent 6235705 commit 6353de6

File tree

3 files changed

+34
-70
lines changed

3 files changed

+34
-70
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ protected function _getCustomerId($email, $websiteCode)
184184
{
185185
$email = strtolower(trim($email));
186186

187-
if ($this->configShare->isGlobalScope() && $this->_customerStorage->getCustomerIdByEmail($email)) {
188-
return $this->_customerStorage->getCustomerIdByEmail($email);
189-
}
190-
191187
if (isset($this->_websiteCodeToId[$websiteCode])) {
192188
$websiteId = $this->_websiteCodeToId[$websiteCode];
193189
return $this->_customerStorage->getCustomerId($email, $websiteId);

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

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\CustomerImportExport\Model\ResourceModel\Import\Customer;
77

8-
use Magento\Customer\Api\CustomerRepositoryInterface;
8+
use Magento\Customer\Model\Config\Share;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection;
1011
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
1112
use Magento\Framework\DataObject;
@@ -30,11 +31,6 @@ class Storage
3031
*/
3132
protected $_customerIds = [];
3233

33-
/**
34-
* @var array
35-
*/
36-
private $customerIdsByEmail = [];
37-
3834
/**
3935
* Number of items to fetch from db in one query
4036
*
@@ -67,26 +63,26 @@ class Storage
6763
private $customerStoreIds = [];
6864

6965
/**
70-
* @var CustomerRepositoryInterface
66+
* @var Share
7167
*/
72-
private $customerRepository;
68+
private $configShare;
7369

7470
/**
7571
* @param CustomerCollectionFactory $collectionFactory
76-
* @param CustomerRepositoryInterface $customerRepository
7772
* @param array $data
73+
* @param Share|null $configShare
7874
*/
7975
public function __construct(
8076
CustomerCollectionFactory $collectionFactory,
81-
CustomerRepositoryInterface $customerRepository,
82-
array $data = []
77+
array $data = [],
78+
?Share $configShare = null
8379
) {
8480
$this->_customerCollection = isset(
8581
$data['customer_collection']
8682
) ? $data['customer_collection'] : $collectionFactory->create();
8783
$this->_pageSize = isset($data['page_size']) ? (int) $data['page_size'] : 0;
8884
$this->customerCollectionFactory = $collectionFactory;
89-
$this->customerRepository = $customerRepository;
85+
$this->configShare = $configShare ?? ObjectManager::getInstance()->get(Share::class);
9086
}
9187

9288
/**
@@ -134,9 +130,14 @@ public function addCustomerByArray(array $customer): Storage
134130
if (!isset($this->customerStoreIds[$email])) {
135131
$this->customerStoreIds[$email] = [];
136132
}
137-
$websiteId = (int) $customer['website_id'];
138-
$this->_customerIds[$email][$websiteId] = (int) $customer['entity_id'];
139-
$this->customerStoreIds[$email][$websiteId] = $customer['store_id'] ?? null;
133+
if ($this->configShare->isGlobalScope()) {
134+
$this->_customerIds[$email] = (int) $customer['entity_id'];
135+
$this->customerStoreIds[$email]= $customer['store_id'] ?? null;
136+
} else {
137+
$websiteId = (int) $customer['website_id'];
138+
$this->_customerIds[$email][$websiteId] = (int) $customer['entity_id'];
139+
$this->customerStoreIds[$email][$websiteId] = $customer['store_id'] ?? null;
140+
}
140141

141142
return $this;
142143
}
@@ -172,30 +173,15 @@ public function getCustomerId(string $email, int $websiteId)
172173
$email = mb_strtolower($email);
173174
$this->loadCustomerData($email, $websiteId);
174175

175-
if (isset($this->_customerIds[$email][$websiteId])) {
176-
return $this->_customerIds[$email][$websiteId];
176+
if ($this->configShare->isGlobalScope() && isset($this->_customerIds[$email])) {
177+
return $this->_customerIds[$email];
177178
}
178179

179-
return false;
180-
}
181-
182-
/**
183-
* Find customer ID by email.
184-
*
185-
* @param string $email
186-
* @return bool|int
187-
*/
188-
public function getCustomerIdByEmail(string $email)
189-
{
190-
if (!isset($this->customerIdsByEmail[$email])) {
191-
try {
192-
$this->customerIdsByEmail[$email] = $this->customerRepository->get($email)->getId();
193-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
194-
$this->customerIdsByEmail[$email] = false;
195-
}
180+
if (!$this->configShare->isGlobalScope() && isset($this->_customerIds[$email][$websiteId])) {
181+
return $this->_customerIds[$email][$websiteId];
196182
}
197183

198-
return $this->customerIdsByEmail[$email];
184+
return false;
199185
}
200186

201187
/**
@@ -254,8 +240,13 @@ public function prepareCustomers(array $customersToFind): void
254240
$this->_customerIds[$email] = [];
255241
$this->customerStoreIds[$email] = [];
256242
}
257-
$this->_customerIds[$email][$websiteId] = null;
258-
$this->customerStoreIds[$email][$websiteId] = null;
243+
if ($this->configShare->isGlobalScope()) {
244+
$this->_customerIds[$email] = null;
245+
$this->customerStoreIds[$email] = null;
246+
} else {
247+
$this->_customerIds[$email][$websiteId] = null;
248+
$this->customerStoreIds[$email][$websiteId] = null;
249+
}
259250
}
260251
}
261252
if (!$identifiers) {
@@ -289,7 +280,11 @@ private function loadCustomerData(string $email, int $websiteId): void
289280
*/
290281
private function isLoadedCustomerData(string $email, int $websiteId): bool
291282
{
292-
return array_key_exists($email, $this->_customerIds)
293-
&& array_key_exists($websiteId, $this->_customerIds[$email]);
283+
if ($this->configShare->isGlobalScope()) {
284+
return array_key_exists($email, $this->_customerIds);
285+
} else {
286+
return array_key_exists($email, $this->_customerIds)
287+
&& array_key_exists($websiteId, $this->_customerIds[$email]);
288+
}
294289
}
295290
}

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -471,33 +471,6 @@ public function testValidateRowForUpdate(array $rowData, array $errors, $isValid
471471
}
472472
}
473473

474-
/**
475-
* @dataProvider validateRowForUpdateDataProvider
476-
*
477-
* @param array $rowData
478-
* @param array $errors
479-
* @param boolean $isValid
480-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
481-
*/
482-
public function testValidateRowForUpdateGlobalCustomer(array $rowData, array $errors, $isValid = false)
483-
{
484-
$this->_model->setParameters(['behavior' => Import::BEHAVIOR_ADD_UPDATE]);
485-
486-
$this->configShare->expects($this->once())
487-
->method('isGlobalScope')
488-
->willReturn(true);
489-
490-
$this->customerStorage->expects($this->exactly(2))
491-
->method('getCustomerIdByEmail')
492-
->willReturn(1);
493-
494-
if ($isValid) {
495-
$this->assertTrue($this->_model->validateRow($rowData, 0));
496-
} else {
497-
$this->assertFalse($this->_model->validateRow($rowData, 0));
498-
}
499-
}
500-
501474
/**
502475
* Test Address::validateRow()
503476
* with 2 rows with identical PKs in case when add/update behavior is performed

0 commit comments

Comments
 (0)