Question

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?

Was it helpful?

Solution 2

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>

OTHER TIPS

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top