2

When customer submit his email in Forgot Password page he is redirected to the Login or Create an Account page. How could I redirect users to the Homepage or to the Onepage Checkout page?

2 Answers 2

5

This one is a bit tricky without rewriting the controller action but this should work. I called my example extension Emzee_ForgotPasswordRedirect.

What it does: after the normal action for creating the forgott password email and redirect instruction has happened, an observer hooks into the postdispatch event of the action, checks if an success action (and no error message) is saved in the customer session and overwrites the redirect to redirect to the homepage.

Caveat: checking for the session messages is a bit hacky but there is no other way to tell whether the forgot password action was successful or not.

XML extension activation file app/etc/modules/Emzee_ForgotPasswordRedirect.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Emzee_ForgotPasswordRedirect>
            <active>true</active>
            <codePool>community</codePool>
            <depends></depends>
        </Emzee_ForgotPasswordRedirect>
    </modules>
</config>

XML extension configuration file app/code/community/Emzee/ForgotPasswordRedirect/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Emzee_ForgotPasswordRedirect>
            <version>1.0.0</version>
        </Emzee_ForgotPasswordRedirect>
    </modules>
    <frontend>
        <events>
            <controller_action_postdispatch_customer_account_forgotpasswordpost>
                <observers>
                    <emzee_forgotpasswordredirect>
                        <class>emzee_forgotpasswordredirect/observer</class>
                        <method>setForgotPasswordRedirect</method>
                    </emzee_forgotpasswordredirect>
                </observers>
            </controller_action_postdispatch_customer_account_forgotpasswordpost>
        </events>
    </frontend>
    <global>
        <models>
            <emzee_forgotpasswordredirect>
                <class>Emzee_ForgotPasswordRedirect_Model</class>
            </emzee_forgotpasswordredirect>
        </models>
    </global>
</config>

Observer app/code/community/Emzee/ForgotPasswordRedirect/Model/Observer.php:

<?php

class Emzee_ForgotPasswordRedirect_Model_Observer
{
    /**
     * @param Varien_Event_Observer $observer
     * @return Emzee_ForgotPasswortRedirect_Model_Observer
     */
    public function setForgotPasswordRedirect(Varien_Event_Observer $observer)
    {
        $controller = $observer->getEvent()->getControllerAction();
        $sessionMessages = Mage::getSingleton('customer/session')->getMessages();

        if ($sessionMessages->count(Mage_Core_Model_Message::SUCCESS) > 0 &&
            $sessionMessages->count(Mage_Core_Model_Message::ERROR) === 0) {
            $controller->setRedirectWithCookieCheck('/');    
        }

        return $this;
    }
}

If you want to redirect to the checkout instead to the homepage, replace

$controller->setRedirectWithCookieCheck('/');

with

$controller->setRedirectWithCookieCheck('checkout/onepage');
2
  • This look promising. Do you know if this will work with Magento 2?
    – Ahdee
    Sep 24, 2017 at 16:08
  • 1
    Sorry, didn't have time to look into it. Please let us know if you tried it. Oct 7, 2017 at 12:41
1

I changed the default\custom-template\template\persistent\customer\form\login.phtml content and added this code to redirect users to the checkout page:

    <script type="text/javascript">
//<![CDATA[
setTimeout(function(){ 
location.href = 'http://exemple.com/checkout/onepage/'}, 5000);
//]]>
    </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.