Magento 1 redirect to home page after login

Hi,
I had to do a simple redirect to home page after customer is logged in, instead of him going to customer account page. The way you do it is using an observer. Magento 1 has an event that fires after login is completed, and this is the event that we’d need. First change the customer settings in system configuration, set Redirect Customer to Account Dashboard after Logging in to No (it’s in the System->Configuration->Customer->Customer Configuration section).

Then make a small extension or if you already have made one add this part in the config.xml:


...
<frontend>
    <events>
        <observers>
            <controller_action_postdispatch_customer_account_loginPost>
                 <my_login_redirect>
                        <type>singleton</type>
                        <class>my_extension/observer</class>
                        <method>homeRedirect</method>
                 </my_login_redirect>
            </controller_action_postdispatch_customer_account_loginPost>
        </observers>
    </events>
</frontend>
...

This is the first part. We need to catch the event that signifies that login is finished, so we catch Magento’s controller postdispatch event on loginPostAction. Now we do the observer part that actually redirects our customer:

<?php
class My_Extension_Model_Observer{
    
    public function homeRedirect(Varien_Event_Observer $observer){
            Mage::app()->getResponse()->setRedirect(Mage::getUrl());
    }
}

And voila! Your customer will now be redirected to the home after he logs in. I will put the small extension for download later on.

Cheers 🙂

Published by Iva Korlevic

I'm a web programmer that started working with web pages in 2008 by programming simple HTML/CSS webpages. I finished Faculty of electrical engineering in April 2010 and started working in Inchoo in May 2010. During the time in Inchoo I worked on Zend applications, Magento stores and a few Wordpress projects. I left Inchoo in January 2012 and worked for a couple of months in Gauss Informatika as Zend teacher and team leader. In May 2012 I left Gauss Informatika and joined the team at NTH Media. For next 6 months I worked on various mobile and Wordpress projects. In the February 2013 together with MArin Blazevic I opened Proodos. I'm still continuing my work as Zend and Magento programmer. In summer 2015 I also started to work for Webbite Media GMBH and on 19th August 2015 I passed Magento Certification Exam and am now Magento Certified Developer.

Leave a comment

Your email address will not be published. Required fields are marked *