Skip to content

Commit 10db0d1

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

File tree

4 files changed

+44
-67
lines changed

4 files changed

+44
-67
lines changed

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
namespace Magento\CustomerImportExport\Model\Import;
88

9-
use Magento\Customer\Model\Config\Share;
10-
use Magento\Framework\App\ObjectManager;
119
use Magento\Framework\Validator\EmailAddress;
1210
use Magento\Framework\Validator\ValidateException;
1311
use Magento\Framework\Validator\ValidatorChain;
@@ -89,11 +87,6 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit
8987
*/
9088
protected $masterAttributeCode = '_email';
9189

92-
/**
93-
* @var Share
94-
*/
95-
private $configShare;
96-
9790
/**
9891
* @param \Magento\Framework\Stdlib\StringUtils $string
9992
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -106,7 +99,6 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit
10699
* @param \Magento\Eav\Model\Config $eavConfig
107100
* @param \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory
108101
* @param array $data
109-
* @param Share|null $configShare
110102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
111103
*/
112104
public function __construct(
@@ -120,8 +112,7 @@ public function __construct(
120112
\Magento\ImportExport\Model\Export\Factory $collectionFactory,
121113
\Magento\Eav\Model\Config $eavConfig,
122114
\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory,
123-
array $data = [],
124-
?Share $configShare = null
115+
array $data = []
125116
) {
126117
$this->_storageFactory = $storageFactory;
127118
parent::__construct(
@@ -136,7 +127,6 @@ public function __construct(
136127
$eavConfig,
137128
$data
138129
);
139-
$this->configShare = $configShare ?? ObjectManager::getInstance()->get(Share::class);
140130
$this->addMessageTemplate(self::ERROR_WEBSITE_IS_EMPTY, __('Please specify a website.'));
141131
$this->addMessageTemplate(
142132
self::ERROR_EMAIL_IS_EMPTY,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Magento\CustomerImportExport\Model\Import;
88

9-
use Magento\Customer\Model\Config\Share;
109
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites as CountryWithWebsitesSource;
1110
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1211
use Magento\Framework\App\ObjectManager;
@@ -274,7 +273,6 @@ class Address extends AbstractCustomer
274273
* @param CountryWithWebsitesSource|null $countryWithWebsites
275274
* @param AddressStorage|null $addressStorage
276275
* @param Processor|null $indexerProcessor
277-
* @param Share|null $configShare
278276
*
279277
* @SuppressWarnings(PHPMD.NPathComplexity)
280278
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -299,8 +297,7 @@ public function __construct(
299297
array $data = [],
300298
?CountryWithWebsitesSource $countryWithWebsites = null,
301299
?AddressStorage $addressStorage = null,
302-
?Processor $indexerProcessor = null,
303-
?Share $configShare = null
300+
?Processor $indexerProcessor = null
304301
) {
305302
$this->_customerFactory = $customerFactory;
306303
$this->_addressFactory = $addressFactory;
@@ -328,8 +325,7 @@ public function __construct(
328325
$collectionFactory,
329326
$eavConfig,
330327
$storageFactory,
331-
$data,
332-
$configShare
328+
$data
333329
);
334330

335331
$this->_entityTable = isset(

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

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CustomerImportExport\Model\ResourceModel\Import\Customer;
77

88
use Magento\Customer\Model\Config\Share;
9-
use Magento\Framework\App\ObjectManager;
109
use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection;
1110
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
1211
use Magento\Framework\DataObject;
@@ -69,20 +68,20 @@ class Storage
6968

7069
/**
7170
* @param CustomerCollectionFactory $collectionFactory
71+
* @param Share $configShare
7272
* @param array $data
73-
* @param Share|null $configShare
7473
*/
7574
public function __construct(
7675
CustomerCollectionFactory $collectionFactory,
77-
array $data = [],
78-
?Share $configShare = null
76+
Share $configShare,
77+
array $data = []
7978
) {
8079
$this->_customerCollection = isset(
8180
$data['customer_collection']
8281
) ? $data['customer_collection'] : $collectionFactory->create();
8382
$this->_pageSize = isset($data['page_size']) ? (int) $data['page_size'] : 0;
8483
$this->customerCollectionFactory = $collectionFactory;
85-
$this->configShare = $configShare ?? ObjectManager::getInstance()->get(Share::class);
84+
$this->configShare = $configShare;
8685
}
8786

8887
/**
@@ -111,6 +110,16 @@ private function loadCustomersData(array $customerIdentifiers): void
111110
$customers = $collection->getConnection()->fetchAll($chunkSelect);
112111
foreach ($customers as $customer) {
113112
$this->addCustomerByArray($customer);
113+
if (
114+
$this->configShare->isGlobalScope() &&
115+
is_array(current($customerIdentifiers)) &&
116+
count(current($customerIdentifiers)) > 0 &&
117+
isset(current($customerIdentifiers)['website_id']) &&
118+
$customer['website_id'] !== (string) current($customerIdentifiers)['website_id']
119+
) {
120+
$customer['website_id'] = (string) current($customerIdentifiers)['website_id'];
121+
$this->addCustomerByArray($customer);
122+
}
114123
}
115124
}
116125
}
@@ -130,14 +139,9 @@ public function addCustomerByArray(array $customer): Storage
130139
if (!isset($this->customerStoreIds[$email])) {
131140
$this->customerStoreIds[$email] = [];
132141
}
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-
}
142+
$websiteId = (int) $customer['website_id'];
143+
$this->_customerIds[$email][$websiteId] = (int) $customer['entity_id'];
144+
$this->customerStoreIds[$email][$websiteId] = $customer['store_id'] ?? null;
141145

142146
return $this;
143147
}
@@ -173,11 +177,7 @@ public function getCustomerId(string $email, int $websiteId)
173177
$email = mb_strtolower($email);
174178
$this->loadCustomerData($email, $websiteId);
175179

176-
if ($this->configShare->isGlobalScope() && isset($this->_customerIds[$email])) {
177-
return $this->_customerIds[$email];
178-
}
179-
180-
if (!$this->configShare->isGlobalScope() && isset($this->_customerIds[$email][$websiteId])) {
180+
if (isset($this->_customerIds[$email][$websiteId])) {
181181
return $this->_customerIds[$email][$websiteId];
182182
}
183183

@@ -240,13 +240,8 @@ public function prepareCustomers(array $customersToFind): void
240240
$this->_customerIds[$email] = [];
241241
$this->customerStoreIds[$email] = [];
242242
}
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-
}
243+
$this->_customerIds[$email][$websiteId] = null;
244+
$this->customerStoreIds[$email][$websiteId] = null;
250245
}
251246
}
252247
if (!$identifiers) {
@@ -280,11 +275,7 @@ private function loadCustomerData(string $email, int $websiteId): void
280275
*/
281276
private function isLoadedCustomerData(string $email, int $websiteId): bool
282277
{
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-
}
278+
return array_key_exists($email, $this->_customerIds)
279+
&& array_key_exists($websiteId, $this->_customerIds[$email]);
289280
}
290281
}

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Customer\Model\Address\Validator\Postcode;
1111
use Magento\Customer\Model\AddressFactory;
12-
use Magento\Customer\Model\Config\Share;
1312
use Magento\Customer\Model\CustomerFactory;
1413
use Magento\Customer\Model\Indexer\Processor;
1514
use Magento\Customer\Model\ResourceModel\Address\Attribute as AddressAttribute;
@@ -150,16 +149,6 @@ class AddressTest extends TestCase
150149
*/
151150
private $countryWithWebsites;
152151

153-
/**
154-
* @var Share|MockObject
155-
*/
156-
private $configShare;
157-
158-
/**
159-
* @var Storage
160-
*/
161-
private $customerStorage;
162-
163152
/**
164153
* Init entity adapter model
165154
*/
@@ -182,7 +171,6 @@ protected function setUp(): void
182171

183172
->method('getAllOptions')
184173
->willReturn([]);
185-
$this->configShare = $this->createMock(Share::class);
186174
$this->_model = $this->_getModelMock();
187175
$this->errorAggregator = $this->createPartialMock(
188176
ProcessingErrorAggregator::class,
@@ -210,7 +198,7 @@ protected function _getModelDependencies()
210198
->getMock();
211199
$connection = $this->createMock(\stdClass::class);
212200
$attributeCollection = $this->_createAttrCollectionMock();
213-
$this->customerStorage = $this->_createCustomerStorageMock();
201+
$customerStorage = $this->_createCustomerStorageMock();
214202
$customerEntity = $this->_createCustomerEntityMock();
215203
$addressCollection = new Collection(
216204
$this->createMock(EntityFactory::class)
@@ -234,7 +222,7 @@ protected function _getModelDependencies()
234222
'bunch_size' => 1,
235223
'attribute_collection' => $attributeCollection,
236224
'entity_type_id' => 1,
237-
'customer_storage' => $this->customerStorage,
225+
'customer_storage' => $customerStorage,
238226
'customer_entity' => $customerEntity,
239227
'address_collection' => $addressCollection,
240228
'entity_table' => 'not_used',
@@ -400,8 +388,7 @@ protected function _getModelMock()
400388
$this->_getModelDependencies(),
401389
$this->countryWithWebsites,
402390
$this->createMock(\Magento\CustomerImportExport\Model\ResourceModel\Import\Address\Storage::class),
403-
$this->createMock(Processor::class),
404-
$this->configShare
391+
$this->createMock(Processor::class)
405392
);
406393

407394
$property = new \ReflectionProperty($modelMock, '_availableBehaviors');
@@ -460,10 +447,23 @@ public function testValidateRowForUpdate(array $rowData, array $errors, $isValid
460447
{
461448
$this->_model->setParameters(['behavior' => Import::BEHAVIOR_ADD_UPDATE]);
462449

463-
$this->configShare->expects($this->once())
464-
->method('isGlobalScope')
465-
->willReturn(false);
450+
if ($isValid) {
451+
$this->assertTrue($this->_model->validateRow($rowData, 0));
452+
} else {
453+
$this->assertFalse($this->_model->validateRow($rowData, 0));
454+
}
455+
}
466456

457+
/**
458+
* @dataProvider validateRowForUpdateDataProvider
459+
*
460+
* @param array $rowData
461+
* @param array $errors
462+
* @param boolean $isValid
463+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
464+
*/
465+
public function testValidateRowForUpdateGlobalCustomer(array $rowData, array $errors, $isValid = false)
466+
{
467467
if ($isValid) {
468468
$this->assertTrue($this->_model->validateRow($rowData, 0));
469469
} else {

0 commit comments

Comments
 (0)