Jump to content

How can I display the group names of the current logged user?


Ury

Recommended Posts

Greetings,

 

I'm a junior (newbie) website developer and I'm currently working in a Prestashop project.

 

I've been asked to display the name of the groups where the current user belongs to in the header of the shop (header.tpl).

 

I've got zero experience on working with Smarty and I've checked some answers in this forum, but they were solved using older versions of prestashop (i'm using version 1.5.3.1). I'm pretty much lost. Any help would be appreciated.

 

Thanks in advice,

Ury

Link to comment
Share on other sites

Hi Ury,

My advice would be not to do it in smarty, but from blockuserinfo.php.

 

Let me clarify: you first need to grab the data from your php file, then assign it to smarty for the display.

 

FInd the hookTop function in blockuserinfo.php. First, get all of the current customer's groups:

Customer::getGroupsStatic($this->context->customer->id)

 

Now simply get all names with a simple query

 

if( $groups)
{
 $groupsnames = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
 SELECT DISTINCT g.`id_group`, gl.`name`
 FROM `'._DB_PREFIX_.'group` g
 LEFT JOIN `'._DB_PREFIX_.'group_lang` AS gl ON (g.`id_group` = gl.`id_group` AND gl.`id_lang` = '.(int)$this->context->language->id.')
 WHERE g.id_group IN ('.implode(',', $groups).')
 ORDER BY g.`id_group` ASC');
}

 

Of course, assign it to smary at this point, and in the blockuserinfo.tpl access it using your set variable (will be an array, you can use a smarty foreach)

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...