magento2
magento2 copied to clipboard
Reset password email sent from wrong store
Preconditions (*)
- Magento >= 2.3.4 (tested on Magento 2.3.4)
Steps to reproduce (*)
- Login to Magento Backend
- Go to Stores > All Stores and create a new website and a new store associated to that website
- Go to Stores > Configuration > General > Web and use a different domain for the new website
- Go to Stores > Configuration > General > General > Locale Options and set the new store's language to a different one from the default store
- Go to Stores > Configuration > Customers > Customer Configuration > Account Sharing Options and enable account sharing
- Go to Magento Store Frontend in the first (default) store
- Create a customer account
- Go to the second store
- Go to the forgot password page and send the form using the email used in step 6 (create a customer account)
Expected result (*)
- Customer receives an email sent in the correct language
- Customer gets redirected to the login page of the second store view
- The URL in the footer is the one of the second store view
Actual result (*)
- Customer receives an email sent in the language of the store he created his account in
- Customer gets redirected to the login page of the store he created his account in
- The URL in the footer is the one of the store he created his account in
Explanation
The bug seems to have appeared in Magento 2.3.4 after changing the method \Magento\Customer\Model\EmailNotification::passwordResetConfirmation
.
Before Magento 2.3.4, the code did this:
public function passwordResetConfirmation(CustomerInterface $customer)
{
$storeId = $this->storeManager->getStore()->getId();
if (!$storeId) {
$storeId = $this->getWebsiteStoreId($customer);
}
$customerEmailData = $this->getFullCustomerObject($customer);
$this->sendEmailTemplate(
$customer,
self::XML_PATH_FORGOT_EMAIL_TEMPLATE,
self::XML_PATH_FORGOT_EMAIL_IDENTITY,
['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)],
$storeId
);
}
but was changed to this:
public function passwordResetConfirmation(CustomerInterface $customer)
{
$storeId = $customer->getStoreId();
if (!$storeId) {
$storeId = $this->getWebsiteStoreId($customer);
}
$customerEmailData = $this->getFullCustomerObject($customer);
$this->sendEmailTemplate(
$customer,
self::XML_PATH_FORGOT_EMAIL_TEMPLATE,
self::XML_PATH_FORGOT_EMAIL_IDENTITY,
['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)],
$storeId
);
}
The problem si that the customer's store ID is retrieved instead of the current store ID.
I think the issue was introduced in this GitHub issue: https://github.com/magento/magento2/issues/5726 which clearly didn't take into account the multi-website / multi-domain and frontend email.