4

I figured this will be a helpful post (especially to me right now!) and I have not seen it after searching.

First of all, we are using Magento 1.4 - so that may determine capabilities in this case.

I can successfully have Magento redirect to a specific page after login by passing:

/referer/{base64_encoded string for the URL}/

in the query string, and it redirects there just fine after I login.

But, what about a new user? They click on "Create Account", which is a new URL (at least in 1.4), and Magento appears to lose the referer through the navigation process. I.e., after I submit my new account info, I'm redirected not to the desired URL, but to admin home page.

What is the correct way to do this? And if it can't be done (which I would find troublesome) is there a decent workaround?

1

3 Answers 3

0

The page to redirect after creating an account is determined in Mage_Customer_AccountController::_welcomeCustomer():

$successUrl = Mage::getUrl('*/*/index', array('_secure'=>true));
if ($this->_getSession()->getBeforeAuthUrl()) {
    $successUrl = $this->_getSession()->getBeforeAuthUrl(true);
}
return $successUrl;

so you need to save the URL in the customer session as "before_auth_url". The same parameter is also used during login when you specify the referer parameter.

A possible solution is to create an observer for controller_action_predispatch, check for the presence of a custom GET parameter and then set the session value. If you only need the parameter to work on the customer controller, use controller_action_predispatch_customer instead.

1

Have you thought of making a module that could capture and set the referer value in the customer's session - to be used at a later point.

Then after the observer has fired for account registration/login - you could check for the existence of the variable, redirect to the destination and unset the session var.

0

Take a look at magento-1.4/app/code/core/Mage/Customer/controllers/AccountController.php

The login action redirect you using _loginPostRedirect which check $referer = Mage::helper('core')->urlDecode($referer);

/**
 * Login post action
 */
public function loginPostAction()
{
    ....
    $this->_loginPostRedirect();
}

While create customer will just redirect

/**
 * Create customer account action
 */
public function createPostAction()
{
   ....         

if ($customer->isConfirmationRequired()) {
     $customer->sendNewAccountEmail('confirmation', $session->getBeforeAuthUrl());
     $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
     $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
     return;
} else {
     $session->setCustomerAsLoggedIn($customer);
     $url = $this->_welcomeCustomer($customer);
     $this->_redirectSuccess($url);
     return;
}

To solve this you could either rewrite createPostAction() and update the lines above accordingly or see if there is any event/observer trigger.

1
  • You could use controller_action_postdispatch_customer_account_createpost - but you would need to be careful if you have other URLs for registration Jul 1, 2015 at 18:38

Your Answer

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

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