Sunday, January 6, 2013

Redirect back to page after logged-in in Magento

If you need to go back to same page once it logged in ,
that is
your in list page and clicked to sign in link and then you logged in it has to go back to list page its self

Magento has default setting for not to redirect account page if you logged in from default page by defult it will redirect to account dash board

but you need to go page to list page
for that follow the below steps
Open header.phtml add this code at top of the file
 if(!Mage::helper('customer')->isLoggedIn()) {
 $loginback=$this->helper('core/url')->getCurrentUrl();
 $check=strstr($loginback, 'customer/account/login');
 if(!strlen($check)){
 Mage::getSingleton('core/session')->setLoginBackUrl($loginback);
 }
}

override app\\code\\core\\Mage\\Customer\\controllers\\AccountController.php to you local or custom module and add this function
 public function _loginPostRedirect()
    {
        $session = $this->_getSession();

        if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {

            // Set default URL to redirect customer to
            $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
            // Redirect customer to the last page visited after logging in
            if ($session->isLoggedIn()) {
   $backUrlcustom=Mage::getSingleton('core/session')->getLoginBackUrl();
                if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard')) {
                    $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                    if ($referer) {
                        $referer = Mage::helper('core')->urlDecode($referer);
                        if ($this->_isUrlInternal($referer)) {
                            $session->setBeforeAuthUrl($referer);
                        }
                    }
                } else if ($session->getAfterAuthUrl()) {
                    $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
                } else if (strlen($backUrlcustom)) {
     Mage::getSingleton('core/session')->setLoginBackUrl('');
                    $session->setBeforeAuthUrl($backUrlcustom);
                }
            } else {
                $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
            }
        } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) {
            $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl());
        } else {
            if (!$session->getAfterAuthUrl()) {
                $session->setAfterAuthUrl($session->getBeforeAuthUrl());
            }
            if ($session->isLoggedIn()) {
                $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
            }
        }
        $this->_redirectUrl($session->getBeforeAuthUrl(true));
    }

or check it this post
http://www.magentocommerce.com/boards/viewthread/301762/

No comments:

Post a Comment