Skip to content

Commit 57c9f73

Browse files
ENGCOM-5116: #22869 - defaulting customer storeId fix #22893
- Merge Pull Request #22893 from Wirson/magento2:22869-rest-customer-update-store-id-fix - Merged commits: 1. f22ab3c 2. f5bf174
2 parents 211dd25 + f5bf174 commit 57c9f73

File tree

2 files changed

+55
-66
lines changed

2 files changed

+55
-66
lines changed

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ public function save(CustomerInterface $customer, $passwordHash = null)
209209
$customerModel->setId($customer->getId());
210210
$storeId = $customerModel->getStoreId();
211211
if ($storeId === null) {
212-
$customerModel->setStoreId($this->storeManager->getStore()->getId());
212+
$customerModel->setStoreId(
213+
$prevCustomerData ? $prevCustomerData->getStoreId() : $this->storeManager->getStore()->getId()
214+
);
213215
}
214216
// Need to use attribute set or future updates can cause data loss
215217
if (!$customerModel->getAttributeSetId()) {
@@ -277,7 +279,6 @@ public function save(CustomerInterface $customer, $passwordHash = null)
277279
'delegate_data' => $delegatedNewOperation ? $delegatedNewOperation->getAdditionalData() : [],
278280
]
279281
);
280-
281282
return $savedCustomer;
282283
}
283284

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function setUp()
107107
$this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
108108
$this->customerRegistry = $this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
109109
$this->dataObjectHelper = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
110-
$this->customerFactory =
110+
$this->customerFactory =
111111
$this->createPartialMock(\Magento\Customer\Model\CustomerFactory::class, ['create']);
112112
$this->customerSecureFactory = $this->createPartialMock(
113113
\Magento\Customer\Model\Data\CustomerSecureFactory::class,
@@ -193,9 +193,10 @@ protected function setUp()
193193
public function testSave()
194194
{
195195
$customerId = 1;
196-
$storeId = 2;
197196

198-
$customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
197+
$customerModel = $this->createPartialMock(
198+
\Magento\Customer\Model\Customer::class,
199+
[
199200
'getId',
200201
'setId',
201202
'setStoreId',
@@ -210,7 +211,8 @@ public function testSave()
210211
'setFirstFailure',
211212
'setLockExpires',
212213
'save',
213-
]);
214+
]
215+
);
214216

215217
$origCustomer = $this->customer;
216218

@@ -229,14 +231,17 @@ public function testSave()
229231
'setAddresses'
230232
]
231233
);
232-
$customerSecureData = $this->createPartialMock(\Magento\Customer\Model\Data\CustomerSecure::class, [
233-
'getRpToken',
234-
'getRpTokenCreatedAt',
235-
'getPasswordHash',
236-
'getFailuresNum',
237-
'getFirstFailure',
238-
'getLockExpires',
239-
]);
234+
$customerSecureData = $this->createPartialMock(
235+
\Magento\Customer\Model\Data\CustomerSecure::class,
236+
[
237+
'getRpToken',
238+
'getRpTokenCreatedAt',
239+
'getPasswordHash',
240+
'getFailuresNum',
241+
'getFirstFailure',
242+
'getLockExpires',
243+
]
244+
);
240245
$this->customer->expects($this->atLeastOnce())
241246
->method('getId')
242247
->willReturn($customerId);
@@ -268,17 +273,6 @@ public function testSave()
268273
$customerModel->expects($this->once())
269274
->method('getStoreId')
270275
->willReturn(null);
271-
$store = $this->createMock(\Magento\Store\Model\Store::class);
272-
$store->expects($this->once())
273-
->method('getId')
274-
->willReturn($storeId);
275-
$this->storeManager
276-
->expects($this->once())
277-
->method('getStore')
278-
->willReturn($store);
279-
$customerModel->expects($this->once())
280-
->method('setStoreId')
281-
->with($storeId);
282276
$customerModel->expects($this->once())
283277
->method('setId')
284278
->with($customerId);
@@ -310,16 +304,20 @@ public function testSave()
310304

311305
$customerModel->expects($this->once())
312306
->method('setRpToken')
313-
->willReturnMap([
307+
->willReturnMap(
308+
[
314309
['rpToken', $customerModel],
315310
[null, $customerModel],
316-
]);
311+
]
312+
);
317313
$customerModel->expects($this->once())
318314
->method('setRpTokenCreatedAt')
319-
->willReturnMap([
315+
->willReturnMap(
316+
[
320317
['rpTokenCreatedAt', $customerModel],
321318
[null, $customerModel],
322-
]);
319+
]
320+
);
323321

324322
$customerModel->expects($this->once())
325323
->method('setPasswordHash')
@@ -371,32 +369,37 @@ public function testSave()
371369
public function testSaveWithPasswordHash()
372370
{
373371
$customerId = 1;
374-
$storeId = 2;
375372
$passwordHash = 'ukfa4sdfa56s5df02asdf4rt';
376373

377-
$customerSecureData = $this->createPartialMock(\Magento\Customer\Model\Data\CustomerSecure::class, [
378-
'getRpToken',
379-
'getRpTokenCreatedAt',
380-
'getPasswordHash',
381-
'getFailuresNum',
382-
'getFirstFailure',
383-
'getLockExpires',
384-
]);
374+
$customerSecureData = $this->createPartialMock(
375+
\Magento\Customer\Model\Data\CustomerSecure::class,
376+
[
377+
'getRpToken',
378+
'getRpTokenCreatedAt',
379+
'getPasswordHash',
380+
'getFailuresNum',
381+
'getFirstFailure',
382+
'getLockExpires',
383+
]
384+
);
385385
$origCustomer = $this->customer;
386386

387-
$customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
388-
'getId',
389-
'setId',
390-
'setStoreId',
391-
'getStoreId',
392-
'getAttributeSetId',
393-
'setAttributeSetId',
394-
'setRpToken',
395-
'setRpTokenCreatedAt',
396-
'getDataModel',
397-
'setPasswordHash',
398-
'save',
399-
]);
387+
$customerModel = $this->createPartialMock(
388+
\Magento\Customer\Model\Customer::class,
389+
[
390+
'getId',
391+
'setId',
392+
'setStoreId',
393+
'getStoreId',
394+
'getAttributeSetId',
395+
'setAttributeSetId',
396+
'setRpToken',
397+
'setRpTokenCreatedAt',
398+
'getDataModel',
399+
'setPasswordHash',
400+
'save',
401+
]
402+
);
400403
$customerAttributesMetaData = $this->getMockForAbstractClass(
401404
\Magento\Framework\Api\CustomAttributesDataInterface::class,
402405
[],
@@ -447,7 +450,6 @@ public function testSaveWithPasswordHash()
447450
$customerSecureData->expects($this->once())
448451
->method('getLockExpires')
449452
->willReturn('lockExpires');
450-
451453
$this->customer->expects($this->atLeastOnce())
452454
->method('getId')
453455
->willReturn($customerId);
@@ -477,20 +479,6 @@ public function testSaveWithPasswordHash()
477479
->method('create')
478480
->with(['data' => ['customerData']])
479481
->willReturn($customerModel);
480-
$customerModel->expects($this->once())
481-
->method('getStoreId')
482-
->willReturn(null);
483-
$store = $this->createMock(\Magento\Store\Model\Store::class);
484-
$store->expects($this->once())
485-
->method('getId')
486-
->willReturn($storeId);
487-
$this->storeManager
488-
->expects($this->once())
489-
->method('getStore')
490-
->willReturn($store);
491-
$customerModel->expects($this->once())
492-
->method('setStoreId')
493-
->with($storeId);
494482
$customerModel->expects($this->once())
495483
->method('setId')
496484
->with($customerId);

0 commit comments

Comments
 (0)