vue-storefront-1
vue-storefront-1 copied to clipboard
Change validation message for the not existing account (Reset password)
What is the motivation for adding / enhancing this feature?
Currently the validation message, for providing the email that is not in the database, shows:
“No such entity with [email protected], websideID=1”
The content of the message should be more user-friendly.

What are the acceptance criteria
- [ ] Change the validation message to “The account for provided email address: [email protected] doesn't exist”
Can you complete this feature request by yourself?
- [ ] YES
- [x] NO
Which Release Cycle state this refers to? Info for developer.
Pick one option.
- [x] This is a normal feature request. This should be available on https://test.storefrontcloud.io and then after tests this can be added to next Vue Storefront version. In this case Developer should create branch from
developbranch and create Pull Request2. Feature / Improvementback todevelop. - [ ] (Pick this option only if you're sure) This is an important improvement request for current Release Candidate version on https://next.storefrontcloud.io and should be placed in next RC version. In this case Developer should create branch from
releasebranch and create Pull Request3. Stabilisation fixback torelease. - [ ] (Pick this option only if you're sure) This is a critical improvement request for current Stable version on https://demo.storefrontcloud.io and should be placed in next stable version. In this case Developer should create branch from
hotfixormasterbranch and create Pull Request4. Hotfixback tohotfix.
This message comes from Magento backend. We can however translate it using i18n module to whatever message we like to have in the fronted - but when Magento changes it we need to add new translation key etc. I don't like this idea but unfortunately don't have any better idea how to solve this FR
I've added a plugin to Magento, to change the message that is coming from the backend. So you can set your custom error message over there and translate it in the frontend or backend. I'm not sure if you can translate it in the frontend when the message contains some variables like the email address.
For the people who are familiar with Magento, add this to the di.xml in you module:
<!--
Plugin to change the exception message when a unknown email address tries to reset the password
-->
<type name="Magento\Customer\Model\AccountManagement">
<plugin name="customerAccountManagementException" type="Vendor\Module\Plugin\Magento\Customer\Model\AccountManagement" sortOrder="10" disabled="false"/>
</type>
Create the following file: Vendor/Module/Plugin/Magento/Customer/Model/AccountManagement.php and add the following code over there:
<?php
namespace Vendor\Module\Plugin\Magento\Customer\Model;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
/**
* Class AccountManagement
* @package Vendor\Module\Plugin\Magento\Customer\Model
*/
class AccountManagement
{
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;
/**
* AccountManagement constructor.
* @param StoreManagerInterface $storeManager
* @param CustomerRepositoryInterface $customerRepository
*/
public function __construct(
StoreManagerInterface $storeManager,
CustomerRepositoryInterface $customerRepository
) {
$this->storeManager = $storeManager;
$this->customerRepository = $customerRepository;
}
/**
* @param \Magento\Customer\Model\AccountManagement $subject
* @param $email
* @param $template
* @param null $websiteId
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function beforeInitiatePasswordReset(\Magento\Customer\Model\AccountManagement $subject, $email, $template, $websiteId = null)
{
if ($websiteId === null) {
$websiteId = $this->storeManager->getStore()->getWebsiteId();
}
try {
// load customer by email
$customer = $this->customerRepository->get($email, $websiteId);
if ($customer->getId()) {
return [$email, $template, $websiteId];
} else {
throw new NoSuchEntityException(__('The email address does not exist.'));
}
} catch (\Exception $e) {
throw new NoSuchEntityException(__('The email address does not exist.'));
}
}
}
Hi @pkarw !
It can't be just translated by i18n module . Because this notification is called from "core/lib/sync/task.ts:129"
if (!task.silent && jsonResponse.result && hasResponseError(jsonResponse) && !silentMode) { rootStore.dispatch('notification/spawnNotification', { type: 'error', message: i18n.t(getResponseMessage(jsonResponse)), action1: { label: i18n.t('OK') } }) }