vue-storefront-1 icon indicating copy to clipboard operation
vue-storefront-1 copied to clipboard

Change validation message for the not existing account (Reset password)

Open GabiDivante opened this issue 6 years ago • 3 comments

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. Peek 2019-05-09 10-38

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 develop branch and create Pull Request 2. Feature / Improvement back to develop.
  • [ ] (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 release branch and create Pull Request 3. Stabilisation fix back to release.
  • [ ] (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 hotfix or master branch and create Pull Request 4. Hotfix back to hotfix.

GabiDivante avatar May 09 '19 10:05 GabiDivante

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

pkarw avatar May 10 '19 06:05 pkarw

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.'));
        }
    }
}

mikesteeghs avatar Jan 03 '20 08:01 mikesteeghs

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') } }) }

vfito avatar Apr 09 '20 13:04 vfito