1

I have rewritten the customer login function to immediately redirect the customer to a specific category.

The overwritten login function looks like this:

public function loginAction()
{
    parent::loginAction();

    $categoryId = Mage::getStoreConfig('customer_rewrite/customer/target_category_id');
    $storeId = Mage::app()->getStore()->getId();
    $url = $this->_getSeoCategoryUrl($categoryId, $storeId);
    $this->_getSession()->setBeforeAuthUrl($url);
}

This function works perfectly (_getSeoCategoryUrl is a protected function I wrote to create the relevant URL, and is not important for this question, I think) and redirects to the correct category page.

I'm just curious why I had to use setBeforeAuthUrl, and not setAfterAuthUrl - I would like to know why I have to do it like that, since using setAfterAuthUrl results in the user just ending on the usual login landing page.

Any clarification on this would be most welcome.

1 Answer 1

2

You can find your answer looking the code in the controller you've rewritten

Take a look at method _loginPostRedirect(), there you'll see how Magento manages both variables, and, at the end...

 $this->_redirectUrl($session->getBeforeAuthUrl(true));
2
  • Short, concise, clear. I like it!
    – Skytiger
    Apr 26, 2016 at 11:37
  • 1
    Glad it helped ;) Apr 26, 2016 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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