patrizia.vergassola Posted November 5, 2013 Share Posted November 5, 2013 Hello everyone I'm using Prestashop 1.4.8.2. The visitors of my website need to be redirect to the login page after they add a product to the cart. So I've added this function to the CartController.php file: public function init() { parent::init(); if (!self::$cookie->isLogged(false)) { // not logged in if (Tools::getValue('ajax') === 'true' && Tools::getValue('add') === '1') { // ajax cart Tools::redirect('my-account.php'); } else { Tools::redirect('my-account.php'); } [spam-filter] but all I can get is the error I've attached when I try to add a product to the cart. I've already used this function in another site I've developed and it worked great (in the other site I use Prestashop 1.5.0.17). Any idea why I keep getting this error? Thank you in advance! Patrizia Link to comment Share on other sites More sharing options...
PascalVG Posted November 5, 2013 Share Posted November 5, 2013 Hmmm, maybe try : !$this->context->customer->isLogged() instead of !self::$cookie->isLogged(false) Furthermore a small question: if (Tools::getValue('ajax') === 'true' && Tools::getValue('add') === '1') { // ajax cart Tools::redirect('my-account.php'); } else { Tools::redirect('my-account.php'); } What is the use of the if statement here, as the if and the else redirect to the same place...?? pascal Link to comment Share on other sites More sharing options...
patrizia.vergassola Posted November 6, 2013 Author Share Posted November 6, 2013 (edited) Hmmm, maybe try : !$this->context->customer->isLogged() instead of !self::$cookie->isLogged(false) Furthermore a small question: if (Tools::getValue('ajax') === 'true' && Tools::getValue('add') === '1') { // ajax cart Tools::redirect('my-account.php'); } else { Tools::redirect('my-account.php'); } What is the use of the if statement here, as the if and the else redirect to the same place...?? pascal I took this code from the module requirelogin This is the original code: if (!self::$cookie->isLogged(false)) { // not logged in if (Tools::getValue('ajax') === 'true' && Tools::getValue('add') === '1') { // ajax cart die('{"hasError" : true, "errors" : ["' . Tools::displayError('Registrati per acquistare o accedi al tuo account.', false) . '"]}'); } else { $this->errors[] = Tools::displayError('Registrati per acquistare o accedi al tuo account.'); } } Using this one it works perfectly: I get an alert saying that I need to register to add a product to my cart. The only thing is I want a redirect to the login page, not an alert. The problem relies in Tools redirect command I think... Edited November 6, 2013 by patrizia.vergassola (see edit history) 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