Skip to content

Commit 60074ee

Browse files
committed
Merge remote-tracking branch 'origin/MC-30650' into 2.4-develop-pr13
2 parents d322368 + 2dea3c5 commit 60074ee

File tree

10 files changed

+462
-91
lines changed

10 files changed

+462
-91
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/CheckTierPricingOfProductsTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<createData entity="Simple_US_Customer" stepKey="customer"/>
3737
<!--Login as admin-->
3838
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
39+
<createData entity="CustomerAccountSharingGlobal" stepKey="setConfigCustomerAccountToGlobal"/>
3940
</before>
4041

4142
<!--Create website, Sore adn Store View-->
@@ -328,6 +329,7 @@
328329
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="DeleteWebsite">
329330
<argument name="websiteName" value="secondWebsite"/>
330331
</actionGroup>
332+
<createData entity="CustomerAccountSharingDefault" stepKey="setConfigCustomerAccountDefault"/>
331333
<actionGroup ref="logout" stepKey="logout"/>
332334

333335
<!--Do reindex and flush cache-->

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,14 @@ public function execute()
348348
['customer' => $customer, 'request' => $this->getRequest()]
349349
);
350350

351-
if (isset($customerData['sendemail_store_id'])) {
351+
if (isset($customerData['sendemail_store_id']) && $customerData['sendemail_store_id'] !== false) {
352352
$customer->setStoreId($customerData['sendemail_store_id']);
353+
try {
354+
$this->customerAccountManagement->validateCustomerStoreIdByWebsiteId($customer);
355+
} catch (LocalizedException $exception) {
356+
throw new LocalizedException(__("The Store View selected for sending Welcome email from".
357+
" is not related to the customer's associated website."));
358+
}
353359
}
354360

355361
// Save customer

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
872872
if ($customer->getId()) {
873873
$customer = $this->customerRepository->get($customer->getEmail());
874874
$websiteId = $customer->getWebsiteId();
875-
876875
if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
877876
throw new InputException(__('This customer already exists in this store.'));
878877
}
@@ -896,13 +895,10 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
896895
$customer->setWebsiteId($websiteId);
897896
}
898897

898+
$this->validateCustomerStoreIdByWebsiteId($customer);
899+
899900
// Update 'created_in' value with actual store name
900901
if ($customer->getId() === null) {
901-
$websiteId = $customer->getWebsiteId();
902-
if ($websiteId && !$this->isCustomerInStore($websiteId, $customer->getStoreId())) {
903-
throw new LocalizedException(__('The store view is not in the associated website.'));
904-
}
905-
906902
$storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
907903
$customer->setCreatedIn($storeName);
908904
}
@@ -1144,6 +1140,22 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
11441140
return in_array($storeId, $ids);
11451141
}
11461142

1143+
/**
1144+
* Validate customer store id by customer website id.
1145+
*
1146+
* @param CustomerInterface $customer
1147+
* @return bool
1148+
* @throws LocalizedException
1149+
*/
1150+
public function validateCustomerStoreIdByWebsiteId(CustomerInterface $customer)
1151+
{
1152+
if (!$this->isCustomerInStore($customer->getWebsiteId(), $customer->getStoreId())) {
1153+
throw new LocalizedException(__('The store view is not in the associated website.'));
1154+
}
1155+
1156+
return true;
1157+
}
1158+
11471159
/**
11481160
* Validate the Reset Password Token for a customer.
11491161
*

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected function setUp()
269269
->getMock();
270270
$this->managementMock = $this->getMockBuilder(AccountManagement::class)
271271
->disableOriginalConstructor()
272-
->setMethods(['createAccount'])
272+
->setMethods(['createAccount', 'validateCustomerStoreIdByWebsiteId'])
273273
->getMock();
274274
$this->addressDataFactoryMock = $this->getMockBuilder(AddressInterfaceFactory::class)
275275
->disableOriginalConstructor()
@@ -522,6 +522,9 @@ public function testExecuteWithExistentCustomer()
522522
->with('customer/*/edit', ['id' => $customerId, '_current' => true])
523523
->willReturn(true);
524524

525+
$this->managementMock->method('validateCustomerStoreIdByWebsiteId')
526+
->willReturn(true);
527+
525528
$this->assertEquals($redirectMock, $this->model->execute());
526529
}
527530

0 commit comments

Comments
 (0)