norseman Posted December 12, 2011 Share Posted December 12, 2011 Hey there all, Thx for reading this. What i am trying to do is the following... depending on the group member that is logging in, I need to redirect the customer to a specific page. I have two groups, Retail and Wholesale. The two groups have no interaction with one another and dont have access to each others areas, so therefore the groups cannot be redirected to the same page, and the client doesnt just want them redirected to the index page. So therefore, I have modded the AuthController.php page to redirect to a specific page, however it is generic, therefore both groups are getting redirected to the same page. This is fine for retailers, however when a wholesaler logs in, presta tells them they cannot view that page. Is there a way in the auth controller to find WHICH group the user is in, and then redirect accordingly? Thanks for your help! Link to comment Share on other sites More sharing options...
doekia Posted December 12, 2011 Share Posted December 12, 2011 Hi, Sure in the controller, once logged the $cookie->id_customer is the id of the customer (assuming logged = 1). With the customer id you can create the customer object $customer = new Customer($cookie->id_customer); with this object you can detect which group is involved. Best, (d)oekia Link to comment Share on other sites More sharing options...
norseman Posted December 12, 2011 Author Share Posted December 12, 2011 Thx for the info! Here is what i have done. in the if statement of if (Tools::isSubmit('SubmitLogin')) which I assume is where the process is to actually log a user in, there is the area to set the cookie parameters. In that section, I added the following line, self::$cookie->groupid = $customer->id_default_group; Things seem to work smoothly, no php errors, however when I get down to if (!Tools::isSubmit('ajax')) { if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } I have changed that to if (!Tools::isSubmit('ajax')) { if ($back = Tools::getValue('back') && $cookie->groupid == 1) { Tools::redirect('25-whitewater-premium-soy-candles'); } else { Tools::redirect('50-whitewater-candle'); }//Tools::redirect($back); Tools::redirect('http://simplethings.ca/en/25-whitewater-premium-soy-candles'); //Tools::redirect('my-account.php'); } My group id of retailers is 1, my group id for wholesalers is 2. Whenever I log in, I am ALWAYS redirected to 50-whitewater-candle page. Any insight on this? Thanks!!!! Link to comment Share on other sites More sharing options...
doekia Posted December 12, 2011 Share Posted December 12, 2011 Note, when you paste code, use the code button or encaptule in [ code ], this helps reading. I think you've lost your mind The initial portion @line:204 on a 1.4.5.1 on pristine AuthController.php if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); change it with if ($back = Tools::getValue('back')) Tools::redirect($back); global $link; if ((int)$customer->id_default_group == 1) Tools::redirect($link->getCategoryLink(25)); else Tools::redirect($link->getCategoryLink(50)); Unwind all other changes and let us know. FYI, you should refrain tamper with the back parameter since it is used when a user initiate the checkout process, so Presta can return the user to the checkout step seamlessly Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 Hi there, thx for your time. I made those changes on the 1.4.4.1 AuthController.php, original version. However, its like the change isnt even there, all logins get redirected to my-account.php Any other ideas? Link to comment Share on other sites More sharing options...
doekia Posted December 13, 2011 Share Posted December 13, 2011 Pretty puzzled since we have no more line that goes to my-account!! What's about with the test and back portion commented? Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 I have also changed back to the original, and then added that code to the second if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); around line 268, and still no go..., the only other area in this file is around line 38, and that doesnt work either... this isnt making any sense... and i have cleaned out my cache, so its not a caching issue... Thanks Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 Pretty puzzled since we have no more line that goes to my-account!! What's about with the test and back portion commented? I will try that, thx Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 OK... so heres the final fix... In version 1.4.4.1, around line 266, there will be if (!Tools::isSubmit('ajax')) { if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } had to change to if (!Tools::isSubmit('ajax')) { //if ($back = Tools::getValue('back')) // Tools::redirect($back); //Tools::redirect('my-account.php'); //global $link; if ((int)$customer->id_default_group == 1) Tools::redirect('25-whitewater-premium-soy-candles'); else Tools::redirect('50-whitewater-candle'); } Actually your $link->getCategoryLink wouldnt work, not sure why... but at least its working now! Thanks for your help! NOTE: I noticed that i had commented out the global $link, and thought that was the issue, however uncommented it, changed the code to getCategoryLink(25) and still no love. Link to comment Share on other sites More sharing options...
doekia Posted December 13, 2011 Share Posted December 13, 2011 During ajax call $link is not inited. just to: $link = new Link(); should do Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 Thx I will try that... how do I marked this post as solved? Link to comment Share on other sites More sharing options...
norseman Posted December 13, 2011 Author Share Posted December 13, 2011 Nope, still no love. global $link; $link = new Link(); if ((int)$customer->id_default_group == 1) Tools::redirect($link->getCategoryLink(25)); else Tools::redirect($link->getCategoryLink(50)); Not a big deal, I will just have to remember if I change the name of the page, I will have to change the AuthController file. 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