arkantos_a Posted June 14, 2023 Share Posted June 14, 2023 (edited) When I enter an existing URL of a category without login in my private prestashop website, fronController redirects to login page (THIS IS OK): if (!$this->context->customer->isLogged() && $this->php_self != 'authentication' && $this->php_self != 'password') { Tools::redirect('index.php?controller=authentication?back=my-account'); But after login I would like to come back to the first URL of my category. Can you help with this? Thanks in advance PD: I have tried this without succes Tools::redirect('index.php?controller=authentication?back='.$_SERVER["REQUEST_URI"]); Edited June 14, 2023 by arkantos_a Update (see edit history) Link to comment Share on other sites More sharing options...
AddWeb Solution Posted July 27, 2023 Share Posted July 27, 2023 Before redirecting the user to the login page, store the current category URL in a session variable: if (!$this->context->customer->isLogged() && $this->php_self != 'authentication' && $this->php_self != 'password') { // Store the current category URL in a session variable $category_url = $_SERVER["REQUEST_URI"]; $this->context->cookie->category_url = $category_url; Tools::redirect('index.php?controller=authentication?back=my-account'); } After a successful login, retrieve the stored category URL from the session and redirect the user back to it: // handle successful login // ... // Check if the session variable with the category URL exists if (isset($this->context->cookie->category_url) && !empty($this->context->cookie->category_url)) { // Retrieve the category URL from the session $category_url = $this->context->cookie->category_url; // Clear the session variable to avoid redirecting the user to the category on future logins $this->context->cookie->category_url = ''; // Redirect the user back to the stored category URL Tools::redirect($category_url); } else { // If no stored category URL found, redirect the user to the default page after login (e.g., My Account) Tools::redirect('index.php?controller=my-account'); } I hope this helps. Thanks! 1 Link to comment Share on other sites More sharing options...
arkantos_a Posted July 27, 2023 Author Share Posted July 27, 2023 3 hours ago, AddWeb Solution said: Before redirecting the user to the login page, store the current category URL in a session variable: if (!$this->context->customer->isLogged() && $this->php_self != 'authentication' && $this->php_self != 'password') { // Store the current category URL in a session variable $category_url = $_SERVER["REQUEST_URI"]; $this->context->cookie->category_url = $category_url; Tools::redirect('index.php?controller=authentication?back=my-account'); } After a successful login, retrieve the stored category URL from the session and redirect the user back to it: // handle successful login // ... // Check if the session variable with the category URL exists if (isset($this->context->cookie->category_url) && !empty($this->context->cookie->category_url)) { // Retrieve the category URL from the session $category_url = $this->context->cookie->category_url; // Clear the session variable to avoid redirecting the user to the category on future logins $this->context->cookie->category_url = ''; // Redirect the user back to the stored category URL Tools::redirect($category_url); } else { // If no stored category URL found, redirect the user to the default page after login (e.g., My Account) Tools::redirect('index.php?controller=my-account'); } I hope this helps. Thanks! Thanks you very much, following those steps works perfectly! Link to comment Share on other sites More sharing options...
AddWeb Solution Posted July 28, 2023 Share Posted July 28, 2023 18 hours ago, arkantos_a said: Thanks you very much, following those steps works perfectly! Great to hear this! Could you Kindly add a cup emoji 🏆 to my post? Thanks! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now