Magento “Forgot Password” email sent in wrong language

耗尽温柔 提交于 2019-12-01 19:27:01

I have same problem in magento v1.5. After a long research i found this solution and its working for me.

Mage/Customer/Model/Customer.php

in this file i have make some changes as following.
find this line of code
if (!$storeId) 
{
    $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
}

and replace with

$storeId = ($storeId == '0')?$this->getSendemailStoreId():$storeId;
if ($this->getWebsiteId() != '0' && $storeId == '0') 
{
    $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
    reset($storeIds);
    $storeId = current($storeIds);
}

I had the same problem, and it looks like user2282917's solution works with a little modify:

You should edit the sendPasswordResetConfirmationEmail function in the Customer.php not the sendNewAccountEmail. Try to replace the code there, and it will working.

Overwrite the forgotPasswordPostAction controller on the AccountController.php. You need to set the correct store id so that the locale will be used.

/**
 * Forgot customer password action
 */
public function forgotPasswordPostAction()
{
    $email = (string) $this->getRequest()->getPost('email');
    if ($email) {
        if (!Zend_Validate::is($email, 'EmailAddress')) {
            $this->_getSession()->setForgottenEmail($email);
            $this->_getSession()->addError($this->__('Invalid email address.'));
            $this->_redirect('*/*/forgotpassword');
            return;
        }

        /** @var $customer Mage_Customer_Model_Customer */
        $customer = $this->_getModel('customer/customer')
            ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
            ->loadByEmail($email);

        if ($customer->getId()) {
            try {
                $newResetPasswordLinkToken =  $this->_getHelper('customer')->generateResetPasswordLinkToken();
                $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);

                // Add store ID so that correct locale will be set
                $customer->setStoreId(Mage::app()->getStore()->getId());

                $customer->sendPasswordResetConfirmationEmail();
            } catch (Exception $exception) {
                $this->_getSession()->addError($exception->getMessage());
                $this->_redirect('*/*/forgotpassword');
                return;
            }
        }
        $this->_getSession()
            ->addSuccess( $this->_getHelper('customer')
            ->__('If there is an account associated with %s you will receive an email with a link to reset your password.',
                $this->_getHelper('customer')->escapeHtml($email)));
        $this->_redirect('*/*/');
        return;
    } else {
        $this->_getSession()->addError($this->__('Please enter your email.'));
        $this->_redirect('*/*/forgotpassword');
        return;
    }
}

In the below file Mage/Customer/Model/Customer.php

In sendPasswordResetConfirmationEmail function() change the

$storeId = $this->getStoreId();

to

$storeId = Mage::app()->getStore()->getStoreId();

Thanks

In our case... We found that when a Customer Account was created by Admin the "email send from" option was not saved and only used for the first account creation email. Any subsequent email sent are sent from the default store view of the website the customer was allocated.

The real problem is how, when the customer store id is identified when none is set.

The method sendPasswordResetConfirmationEmail (Magento 1.9.1) when the store id is 0 (admin or not set), defaults to _getWebsiteStoreId which will return the first store id associated to that website.

The problem is that Magento assumes the first store id associated with the website id is the default store... We found this is not the case when a Sort Order is set against the store record.

Simply put make sure your default store assocaited with a web site is also specified with a sort order of 0.

Hope this link will be usefull to you

In link they have used New Password but Instead of New Password Use Forgot Password template In step 4

Thanks..

The password reset email is send in Mage_Customer_Model_Customer::_sendEmailTemplate(). Here the emailtemplate is loaded. If it was loaded in admin in "Systemn > Transactional Emails" and configured to be used, your template will be used.

Else the default template is loaded from file in Mage_Core_Model_Email_Template::sendTransactional. This is done using $this->loadDefault($templateId, $localeCode); The template ist loaded using

$templateText = Mage::app()->getTranslator()->getTemplateFile(
            $data['file'], 'email', $locale
        );

Here locale folders are checked in following order:

  1. Specified locale
  2. Locale of default store
  3. en_US locale

The first matched locale is chosen. As Mage::app() doesn't know about the store which was passed with the emailtemplate, the default defaultstore is loaded, which is german in your case. It has nothing to do with the order of the locale folders.

So in your case I suggest to check if your emailtemplate is selected in admin configuration in "System > Config > Customerconfiguration > Password Options" or use Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_REMIND_EMAIL_TEMPLATE, $storeId) if it is set for your store.

The reason for why you are receiving the email templates in another language than the one expected is dependent of the language in which you first created your account. Try to check this to be in your own language when you first created the account.

Check this under Customers> Account Information to see how your account was created.

/Kalif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!