0

I try to get the last visited page, for example I want to know if the last visited page was Checkout, if the Checkout page was last visited page then redirect customer after registration or login to the checkout page, else redirect to the my account.

this is my code:

   public function customerLogin(Varien_Event_Observer $observer)
   {    
       if(Mage::getSingleton('core/session')->getIsFromCart() == 1){
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage'));
            Mage::app()->getResponse()->sendResponse();
            exit;
         }

         else{ 
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
         Mage::getSingleton('core/session')->setIsFromCart('0');
   }
1

Try something like that in your observer:

public function customerLogin(Varien_Event_Observer $observer)
   {    
       $lastUrl = Mage::getSingleton('core/session')->getLastUrl();
       if(preg_match("#onestepcheckout/index#", $lastUrl)){
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage'));
            Mage::app()->getResponse()->sendResponse();
            exit;
         }

         else{ 
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }

   }
| improve this answer | |
  • Hi Alex, thank you for your answer, I think you help me last time with this code, I have a small issues with this code, can you tell me where I can put this code? – Robert Mar 4 '16 at 18:15
  • check the edited answer – Alex Constantinescu Mar 4 '16 at 18:23
  • is very strange we can talk in private? – Robert Mar 4 '16 at 18:30
  • all i want to do is to check first if the user was in the checkout page before, if is true after login must be redirected to checkout, now with this code is redirect me only to my account, even if I visited checkout page – Robert Mar 4 '16 at 18:34
  • the code from above should do that. What's the link of your checkout page ? – Alex Constantinescu Mar 4 '16 at 18:37

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.