AlexYao Posted October 18, 2010 Share Posted October 18, 2010 I have sorted customer into different groups manually. But I want to know how to show customer group name at Front Office (account page .etc) automatically. For example, add group name which a specific customer belongs to after logged in:Welcome, {$customerName} Log out. You are {GroupName}.Here {GroupName} is what I am looking for. Please help me on this. How to get this cmd?Millions thanks in advance.Alex Link to comment Share on other sites More sharing options...
AlexYao Posted October 18, 2010 Author Share Posted October 18, 2010 I have sorted customer into different groups manually. But I want to know how to show customer group name at Front Office (account page .etc) automatically. For example, add group name which a specific customer belongs to after logged in:Welcome, {$customerName} Log out. You are {GroupName}. Here {GroupName} is what I am looking for. Please help me on this. How to get this cmd?Millions thanks in advance.Alex Link to comment Share on other sites More sharing options...
olea Posted October 18, 2010 Share Posted October 18, 2010 You have a module in the addons :http://addons.prestashop.com/fr/fonctionnalites-front-office/1183-accountgroup.html Link to comment Share on other sites More sharing options...
rocky Posted October 18, 2010 Share Posted October 18, 2010 Topics mergedPrestaShop doesn't provide the customer's group name in the data it provides to templates, so you will need to add it. Add the following code to init.php after $cookie = new Cookie('ps'); if (intval($cookie->id_customer) > 0) { $customer = new Customer(intval($cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $group = new Group(intval($customer->id_default_group)); if (Validate::isLoadedObject($group)) $smarty->assign('groupName', $group->name[intval($cookie->id_lang)]); } } You should then be able to use {$groupName} in any TPL file. 2 Link to comment Share on other sites More sharing options...
AlexYao Posted October 18, 2010 Author Share Posted October 18, 2010 Topics mergedPrestaShop doesn't provide the customer's group name in the data it provides to templates, so you will need to add it. Add the following code to init.php after $cookie = new Cookie('ps'); if (intval($cookie->id_customer) > 0) { $customer = new Customer(intval($cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $group = new Group(intval($customer->id_default_group)); if (Validate::isLoadedObject($group)) $smarty->assign('groupName' => $group->name); } } Ok, thanks Rocky, I will add this and will let you know if it work.thanks again Link to comment Share on other sites More sharing options...
AlexYao Posted October 18, 2010 Author Share Posted October 18, 2010 Hi Rocky, it seems not work in my localhost shop. it shows HTTP 500 error after adding the code you provided. (back to normal when deleted the code)I copy and paste it into init.php file. Nothing changed. Why it doesn't work?is it because of my localhost reason?Pls help me. thanks. Link to comment Share on other sites More sharing options...
rocky Posted October 18, 2010 Share Posted October 18, 2010 I've corrected my code above. Please try again. Link to comment Share on other sites More sharing options...
AlexYao Posted October 18, 2010 Author Share Posted October 18, 2010 Hi Rocky,No 500 error this time but visible group name is not true name as set in BO.No matter which group a customer in, it always shows Array by name instead of actual group name.Pls help. Thanks for quick responce. Link to comment Share on other sites More sharing options...
rocky Posted October 18, 2010 Share Posted October 18, 2010 I've updated my code again to select the name for the current language. Hopefully, it will work this time. Link to comment Share on other sites More sharing options...
AlexYao Posted October 18, 2010 Author Share Posted October 18, 2010 yes, it worked now this time. Perfect!!Thank you much. Wonderfull work, Rocky.Alex Link to comment Share on other sites More sharing options...
FredActin Posted December 3, 2010 Share Posted December 3, 2010 Hello there,Sorry to wake up this solved topic,I have used Rocky's method successfully on a 1.3 shop.I would like to use it with Prestashop 1.4 alpha 3.The init.php file is slightly different. I tried to insert the snippet of code as follows: // Required for BO cookie path$currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME']));$cookie = new Cookie('psAdmin', substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])));if (intval($cookie->id_customer) > 0){ $customer = new Customer(intval($cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $group = new Group(intval($customer->id_default_group)); if (Validate::isLoadedObject($group)) $smarty->assign('groupName', $group->name[intval($cookie->id_lang)]); }} if (isset($_GET['logout'])) { $url_redirect = ''; $cookie->logout();} I must be missing something because my call from the product.tpl file with {$groupName} doesn't return anything.Any suggestion would be much appreciated! Link to comment Share on other sites More sharing options...
rocky Posted December 5, 2010 Share Posted December 5, 2010 It looks like the code has been moved to classes/FrontController.php in PrestaShop v1.4 Alpha 3. You will need to put it in the init() function there. Link to comment Share on other sites More sharing options...
FredActin Posted December 5, 2010 Share Posted December 5, 2010 Rocky, you are a legend!It works thank you very much :-)Just a note if somebody else wants to do the same things:On the Frontcontroller.php file there are two lines with: $cookie = new Cookie('ps'); Insert the code after the second line (line 119) and it should work :-)Thanks again Link to comment Share on other sites More sharing options...
Arafat Jahan Posted February 20, 2011 Share Posted February 20, 2011 Topics mergedPrestaShop doesn't provide the customer's group name in the data it provides to templates, so you will need to add it. Add the following code to init.php after $cookie = new Cookie('ps'); if (intval($cookie->id_customer) > 0) { $customer = new Customer(intval($cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $group = new Group(intval($customer->id_default_group)); if (Validate::isLoadedObject($group)) $smarty->assign('groupName', $group->name[intval($cookie->id_lang)]); } } Thanks a Lot! You code is perfect and works in my 1.3.6 Vr You should then be able to use {$groupName} in any TPL file. Link to comment Share on other sites More sharing options...
madmike Posted April 18, 2011 Share Posted April 18, 2011 warning $groupName is allready use in product TPL in PS 1.4And it seem have $currentCustomerGroups in PS1.4 from Frontcontroler.php Link to comment Share on other sites More sharing options...
kosmolog Posted September 17, 2011 Share Posted September 17, 2011 After loading the. Tpl {$ groupName} displays "default" on the front office. How do to a group of "default" not display on the front office Link to comment Share on other sites More sharing options...
FredActin Posted September 18, 2011 Share Posted September 18, 2011 You will need to add a condition, something like: {if $groupName == 'default'} You code here to hide the code {/if} Link to comment Share on other sites More sharing options...
Rapture Posted March 17, 2012 Share Posted March 17, 2012 [solved] Link to comment Share on other sites More sharing options...
melriks Posted August 13, 2012 Share Posted August 13, 2012 (edited) Is there an update to this thread for Presta 1.4.8? There is no line for $cookie = new Cookie('ps'); Duh, found it. Now looks like $cookie = new Cookie('ps', '', $cookieLifetime); Line 108. Edited August 13, 2012 by melriks (see edit history) Link to comment Share on other sites More sharing options...
Daaaaad Posted August 26, 2012 Share Posted August 26, 2012 (edited) Here is a proper way to have customer groups in templates (tpl). 1. Create a file called FrontController.php in override/classes 2. Copy/paste the following code in this empty file class FrontController extends FrontControllerCore { public function init() { parent::init(); self::$smarty->assign('customerGroups', parent::getCurrentCustomerGroups()); } } 3. You can now use {$customerGroups} in your templates Edited August 26, 2012 by Daaaaad (see edit history) 2 Link to comment Share on other sites More sharing options...
melriks Posted November 19, 2012 Share Posted November 19, 2012 Just to verify, this works in Prestashop 1.5. Add Daaaaad's code to override/classes/controller FrontController.php. It provided me the array of group id number(s) for the customer. More details at http://melriks.com/prestashop-cms-page-for-certain-groups/ Link to comment Share on other sites More sharing options...
mhu100 Posted December 15, 2012 Share Posted December 15, 2012 (edited) Topics merged PrestaShop doesn't provide the customer's group name in the data it provides to templates, so you will need to add it. Add the following code to init.php after $cookie = new Cookie('ps'); if (intval($cookie->id_customer) > 0) { $customer = new Customer(intval($cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $group = new Group(intval($customer->id_default_group)); if (Validate::isLoadedObject($group)) $smarty->assign('groupName', $group->name[intval($cookie->id_lang)]); } } You should then be able to use {$groupName} in any TPL file. Unfortunately it's not working in Version 1.2.4.0. I don't see anything in FO. Do you have any ideas? Edited December 15, 2012 by mhu100 (see edit history) Link to comment Share on other sites More sharing options...
SuperDuper Posted February 16, 2013 Share Posted February 16, 2013 Just to verify, this works in Prestashop 1.5. Add Daaaaad's code to override/classes/controller FrontController.php. It provided me the array of group id number(s) for the customer. More details at http://melriks.com/p...certain-groups/ Hello, How can you add Group Name in FO?? I have already add the code in "FrontController.php" Then add "{$customerGroups}" in the .tpl files. It shows "Array" on the page. Could you please help?? Thanks. Link to comment Share on other sites More sharing options...
longip Posted April 29, 2013 Share Posted April 29, 2013 How can you show customer group name in PS1.5.4 ? Can somebody please explain ? Link to comment Share on other sites More sharing options...
Pichayutm Posted July 11, 2013 Share Posted July 11, 2013 (edited) Hello, How can you add Group Name in FO?? I have already add the code in "FrontController.php" Then add "{$customerGroups}" in the .tpl files. It shows "Array" on the page. Could you please help?? Thanks. After following the suggestion Daaaaad, I got a phrase "Array" too. Anybody knows how to fix? PS 1.5.2 Edited July 11, 2013 by Pichayutm (see edit history) Link to comment Share on other sites More sharing options...
Pichayutm Posted July 11, 2013 Share Posted July 11, 2013 Find solution here. Thanks to prestashopninja's module http://www.prestashop.com/forums/topic/228277-get-customer-group-id-in-smarty/ Link to comment Share on other sites More sharing options...
xnofub Posted May 13, 2014 Share Posted May 13, 2014 Here is a proper way to have customer groups in templates (tpl). 1. Create a file called FrontController.php in override/classes 2. Copy/paste the following code in this empty file class FrontController extends FrontControllerCore { public function init() { parent::init(); self::$smarty->assign('customerGroups', parent::getCurrentCustomerGroups()); } } 3. You can now use {$customerGroups} in your templates work for 1.5.x version?????? Link to comment Share on other sites More sharing options...
melriks Posted April 5, 2015 Share Posted April 5, 2015 (edited) It worked on 1.5, but does not work in 1.6. Please review this thread as an alternative. https://www.prestashop.com/forums/topic/228277-get-customer-group-id-in-smarty/ I tried this method as well, but it did not work. https://www.prestashop.com/forums/topic/285808-solved-display-a-div-only-for-a-specific-user-group/ Edited April 5, 2015 by melriks (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts