Skip to content

Commit 0d4a9c6

Browse files
ENGCOM-5188: [Backport] #22869 - defaulting customer storeId fix #22895
- Merge Pull Request #22895 from Wirson/magento2:22869-rest-customer-update-store-id-fix-2.2 - Merged commits: 1. 9fd7722
2 parents 3c6ab2e + 9fd7722 commit 0d4a9c6

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
214214

215215
$storeId = $customerModel->getStoreId();
216216
if ($storeId === null) {
217-
$customerModel->setStoreId($this->storeManager->getStore()->getId());
217+
$customerModel->setStoreId(
218+
$prevCustomerData->getStoreId() ?? $this->storeManager->getStore()->getId()
219+
);
218220
}
219221

220222
$this->populateCustomerWithSecureData($customerModel, $passwordHash);

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ public function testSave()
224224
'getId'
225225
]
226226
);
227-
$customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
227+
$customerModel = $this->createPartialMock(
228+
\Magento\Customer\Model\Customer::class,
229+
[
228230
'getId',
229231
'setId',
230232
'setStoreId',
@@ -239,7 +241,8 @@ public function testSave()
239241
'setFirstFailure',
240242
'setLockExpires',
241243
'save',
242-
]);
244+
]
245+
);
243246

244247
$origCustomer = $this->customer;
245248

@@ -362,16 +365,20 @@ public function testSave()
362365

363366
$customerModel->expects($this->once())
364367
->method('setRpToken')
365-
->willReturnMap([
366-
['rpToken', $customerModel],
367-
[null, $customerModel],
368-
]);
368+
->willReturnMap(
369+
[
370+
['rpToken', $customerModel],
371+
[null, $customerModel],
372+
]
373+
);
369374
$customerModel->expects($this->once())
370375
->method('setRpTokenCreatedAt')
371-
->willReturnMap([
372-
['rpTokenCreatedAt', $customerModel],
373-
[null, $customerModel],
374-
]);
376+
->willReturnMap(
377+
[
378+
['rpTokenCreatedAt', $customerModel],
379+
[null, $customerModel],
380+
]
381+
);
375382

376383
$customerModel->expects($this->once())
377384
->method('setPasswordHash')
@@ -432,14 +439,17 @@ public function testSaveWithPasswordHash()
432439
$storeId = 2;
433440
$passwordHash = 'ukfa4sdfa56s5df02asdf4rt';
434441

435-
$customerSecureData = $this->createPartialMock(\Magento\Customer\Model\Data\CustomerSecure::class, [
442+
$customerSecureData = $this->createPartialMock(
443+
\Magento\Customer\Model\Data\CustomerSecure::class,
444+
[
436445
'getRpToken',
437446
'getRpTokenCreatedAt',
438447
'getPasswordHash',
439448
'getFailuresNum',
440449
'getFirstFailure',
441450
'getLockExpires',
442-
]);
451+
]
452+
);
443453
$region = $this->getMockForAbstractClass(
444454
\Magento\Customer\Api\Data\RegionInterface::class,
445455
[],
@@ -481,7 +491,9 @@ public function testSaveWithPasswordHash()
481491
->method('__toArray')
482492
->willReturn(['default_billing', 'default_shipping']);
483493

484-
$customerModel = $this->createPartialMock(\Magento\Customer\Model\Customer::class, [
494+
$customerModel = $this->createPartialMock(
495+
\Magento\Customer\Model\Customer::class,
496+
[
485497
'getId',
486498
'setId',
487499
'setStoreId',
@@ -493,7 +505,8 @@ public function testSaveWithPasswordHash()
493505
'getDataModel',
494506
'setPasswordHash',
495507
'save',
496-
]);
508+
]
509+
);
497510
$customerAttributesMetaData = $this->getMockForAbstractClass(
498511
\Magento\Framework\Api\CustomAttributesDataInterface::class,
499512
[],
@@ -521,7 +534,6 @@ public function testSaveWithPasswordHash()
521534
$this->customerRegistry->expects($this->atLeastOnce())
522535
->method('remove')
523536
->with($customerId);
524-
525537
$this->customerRegistry->expects($this->once())
526538
->method('retrieveSecureData')
527539
->with($customerId)
@@ -544,7 +556,6 @@ public function testSaveWithPasswordHash()
544556
$customerSecureData->expects($this->once())
545557
->method('getLockExpires')
546558
->willReturn('lockExpires');
547-
548559
$this->customer->expects($this->atLeastOnce())
549560
->method('getId')
550561
->willReturn($customerId);

0 commit comments

Comments
 (0)