1

I want to redirect customer to last visiting page after loggedin. My code as far looks like: Config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Virtua_Vcategory>
        <version>1.0.0</version>
    </Virtua_Vcategory>
</modules>
<global>
    <models>
        <virtua_vcategory>
            <class>Virtua_Vcategory_Model</class>
        </virtua_vcategory>
    </models>
    <helpers>
        <virtua_vcategory>
            <class>Virtua_Vcategory_Helper</class>
        </virtua_vcategory>
    </helpers>

    <blocks>
        <virtua_vcategory>
            <class>Virtua_Vcategory_Block</class>
        </virtua_vcategory>
    </blocks>

</global>
<frontend>
    <events>

        <catalog_controller_category_init_after>
            <observers>
                <virtua_vcategory>
                    <type>singleton</type>
                    <class>virtua_vcategory/observer</class>
                    <method>catalogControllerLoadAfter</method>
                </virtua_vcategory>
            </observers>
        </catalog_controller_category_init_after>

        <customer_login>
            <observers>
                <virtua_vcategory>
                    <class>virtua_vcategory/observer</class>
                    <method>customerLogin</method>
                </virtua_vcategory>
            </observers>
        </customer_login>
  </events>
</frontend>
</config>

Observer:

 <?php

 class Virtua_Vcategory_Model_Observer extends Mage_Core_Model_Abstract
 {
   public function catalogControllerLoadAfter(Varien_Event_Observer $observer)
{
    ...

    if (Mage::getSingleton('customer/session')->isLoggedIn()) {

        ...
    }
    else
    {
        $beforeurl = Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());

        MAGE::log($beforeurl );     /****first log*****/

        $route = 'customer/account/login';
        $url = Mage::getUrl($route);
        Mage::app()->getResponse()->setRedirect($url);
    }
}
     public function customerLogin(Varien_Event_Observer $observer)
    {

    $url = Mage::getSingleton('customer/session')->getBeforeAuthUrl();

    MAGE::log($url." after log in");     /*****second log*****/

    Mage::app()->getResponse()->setRedirect($url);
    }
}

And my first log (in catalogControllerLoadAfter() ) showing properly urlin object, but in second log url is overwritting. How can i fix it?

4

There is an option in Magento for that. Go to System > Configuration > Customer Configuration > Login Options and set Redirect Customer to Account Dashboard after Logging in to No

  • I know and its set on No – user3819713 Aug 26 '15 at 13:26
  • The core exactly does what you describe if this option is turned off. It sets the beforeAuthUrl to the page you came from. Try to disable your extension first to check it's not conflicting, and make sure the configuration setting is set on your store view. It should work out of the box. – Mayers Aug 26 '15 at 13:31
  • 1
    Even when i disable my modules still its not what i want. When i logged in magento redirect me to last page i visited when i was previously logged in but i want to redirect to last page when i was guest – user3819713 Aug 26 '15 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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