0

I'm having some difficulties with redirecting a customer, after they login. I'm using the

<customer_login>

event, which is firing my specified function properly.

Here is my function:

public function customerLoginObserve($observer)
{
    //customer is able to login, but no redirection occurs
    $url = 'http://myurl.com';
    $session = Mage::getSingleton('customer/session');
    $session->setAfterAuthUrl($url);
    $session->setBeforeAuthUrl('');

    // Also tried the line below, the UI freezes, and when refreshing the page, customer is logged in:
    //$observer->getEvent()->getFront()->getResponse()->setRedirect($url)->sendResponse();

    //This one also did not work in the login event (freezes UI), but when fired from 
    //other events, works as expected.
    //$observer->getEvent()->getResponse()->setRedirect($url)->sendResponse();
    //exit;
}

EDIT: There doesn't seem to be any errors in the system.log and exception.log If I try to redirect with any of the sendResponse(), that's where the code stops.

Here are a few links that I've looked into, which did not work for me:

Redirect user after login

Magento redirect from all pages if not logged in

Any help appreciated!

  • We will need to see the config for the event I guess. Also is your class being called? Maybe put in some debug to see if it is reaching the observer – David Manners Apr 20 '15 at 18:54
  • hello David, the observer is being called without problems. I've tried logging throughout my function. If I use the setRedirect($url), that's when things seem to go wrong, and logs after that don't get outputted. – bamboo_inside Apr 20 '15 at 18:57
3

I think what you are missing is to send the response after setting the url. This can be done as follows.

Mage::app()->getFrontController()->getResponse()->setRedirect('Your URL');
Mage::app()->getResponse()->sendResponse();
exit;
  • Thanks David, but that still freezes the UI, without redirecting in my case... still no log errors as well, even though the code runs up to those lines without problems. – bamboo_inside Apr 20 '15 at 20:04
  • @bamboo_inside what do you mean by freezes the UI? You might also want to check the general php logs as well and the Magento logs – David Manners Apr 21 '15 at 7:41

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.