Skip to content

Commit 4d78276

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-2212' into AUG102023_PR_pradeep
2 parents ac1247f + cb8609a commit 4d78276

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,11 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
923923
// Make sure we have a storeId to associate this customer with.
924924
if (!$customer->getStoreId()) {
925925
if ($customer->getWebsiteId()) {
926-
$storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
926+
$storeId = null;
927+
$website = $this->storeManager->getWebsite($customer->getWebsiteId());
928+
if ($website->getDefaultStore()) {
929+
$storeId = $website->getDefaultStore()->getId();
930+
}
927931
} else {
928932
$this->storeManager->setCurrentStore(null);
929933
$storeId = $this->storeManager->getStore()->getId();

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public function testCreateAccountWithPasswordHashWithCustomerWithoutStoreId(): v
472472
$website->expects($this->atLeastOnce())
473473
->method('getStoreIds')
474474
->willReturn([1, 2, 3]);
475-
$website->expects($this->once())
475+
$website->expects($this->atMost(2))
476476
->method('getDefaultStore')
477477
->willReturn($store);
478478
$customer = $this->getMockBuilder(Customer::class)
@@ -551,7 +551,7 @@ public function testCreateAccountWithPasswordHashWithLocalizedException(): void
551551
->getMock();
552552
$website->method('getStoreIds')
553553
->willReturn([1, 2, 3]);
554-
$website->expects($this->once())
554+
$website->expects($this->atMost(2))
555555
->method('getDefaultStore')
556556
->willReturn($store);
557557
$customer = $this->getMockBuilder(Customer::class)
@@ -633,7 +633,7 @@ public function testCreateAccountWithPasswordHashWithAddressException(): void
633633
->getMock();
634634
$website->method('getStoreIds')
635635
->willReturn([1, 2, 3]);
636-
$website->expects($this->once())
636+
$website->expects($this->atMost(2))
637637
->method('getDefaultStore')
638638
->willReturn($store);
639639
$customer = $this->getMockBuilder(Customer::class)
@@ -2598,4 +2598,55 @@ public function testValidateCustomerStoreIdByWebsiteIdException(): void
25982598

25992599
$this->assertTrue($this->accountManagement->validateCustomerStoreIdByWebsiteId($customerMock));
26002600
}
2601+
2602+
/**
2603+
* @return void
2604+
* @throws LocalizedException
2605+
*/
2606+
public function testCompanyAdminWebsiteDoesNotHaveStore(): void
2607+
{
2608+
$this->expectException(LocalizedException::class);
2609+
$this->expectExceptionMessage('The store view is not in the associated website.');
2610+
2611+
$websiteId = 1;
2612+
$customerId = 1;
2613+
$customerEmail = 'email@email.com';
2614+
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
2615+
2616+
$website = $this->getMockBuilder(Website::class)
2617+
->disableOriginalConstructor()
2618+
->getMock();
2619+
$website->method('getStoreIds')
2620+
->willReturn([]);
2621+
$website->expects($this->atMost(1))
2622+
->method('getDefaultStore')
2623+
->willReturn(null);
2624+
$customer = $this->getMockBuilder(Customer::class)
2625+
->disableOriginalConstructor()
2626+
->getMock();
2627+
$customer->expects($this->atLeastOnce())
2628+
->method('getId')
2629+
->willReturn($customerId);
2630+
$customer->expects($this->once())
2631+
->method('getEmail')
2632+
->willReturn($customerEmail);
2633+
$customer->expects($this->atLeastOnce())
2634+
->method('getWebsiteId')
2635+
->willReturn($websiteId);
2636+
$customer->method('getStoreId')
2637+
->willReturnOnConsecutiveCalls(null, null, 1);
2638+
$this->customerRepository
2639+
->expects($this->once())
2640+
->method('get')
2641+
->with($customerEmail)
2642+
->willReturn($customer);
2643+
$this->share->method('isWebsiteScope')
2644+
->willReturn(true);
2645+
$this->storeManager
2646+
->expects($this->atLeastOnce())
2647+
->method('getWebsite')
2648+
->with($websiteId)
2649+
->willReturn($website);
2650+
$this->accountManagement->createAccountWithPasswordHash($customer, $hash);
2651+
}
26012652
}

0 commit comments

Comments
 (0)