The page, where a customer is redirected to after login, is determined by the function processSubmitAccount of the controller AuthController. In case we need to change the function behavior, we would need to rewrite it. It is also possible to use the hook actionCustomerAccountAdd, but this method is good for new customers only.
The function Tools::redirect(), which serves as a certain wrapper for the construction header(‘Location:’.$url); , is specifically responsible for the redirect. In this function it is used 7 times.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// redirection: if cart is not empty : redirection to the cart if (count($this->context->cart->getProducts(true)) > 0) Tools::redirect('index.php?controller=order&multi-shipping='.(int)Tools::getValue('multi-shipping')); //I advise not to change address here, because if a customer has any items in the cart Prestashop will redirect him to the checkout page. And if this will be some other page the customer can get upset. // else : redirection to the account else Tools::redirect('index.php?controller=my-account'); //here you can put the page which seems the most obvious to you. ….. if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) Tools::redirect('index.php?controller=address'); // if registration type is in two steps, we redirect to register address if ($back = Tools::getValue('back')) Tools::redirect($back); //this redirect works only if there is the parameter back Tools::redirect('index.php?controller=my-account'); if (count($this->context->cart->getProducts(true)) > 0) Tools::redirect('index.php?controller=order&multi-shipping='.(int)Tools::getValue('multi-shipping')); // redirection: if cart is not empty : redirection to the cart else Tools::redirect('index.php?controller=my-account'); // else : redirection to the account |
So, to redirect a customer to some other page you just need to change the argument of the function Tools::redirect.
Partner With Us
Looking for a partner to grow your business? We are the right company to bring your webstore to success.
Talk to Andrey
Hello, Sivaraju!
Sure, we’d be happy to assist. Our manager has just sent you an email.
Hi Team,
Can anyone help to customise login page ( mobile number instead of email ) in lgin page.
Also, you have: Tools::redirectLink()
Hi good article!
But this is to redirect when you create a new account. To change redirections after login the function to search for is called “processSubmitLogin”.
So the path where to do that shoud be… yourprestashop/controllers/front/AuthController.php :P
Hi Alex, thank you for a very nice explanation of the redirect problem in Prestashop.
I would like to ask about redirection after clicking the SubmitLogin and SubmitGuestAccount buttons (1.5.4.0) in case of errors (e.g. when a customer forgets to fill in a field). Where can this redirection be found? Thank you very much. Jana