Jump to content

[SOLVED] Hiding subcategories from excluded user groups


Recommended Posts

Hi all,
Let's say I have the following categories structure:

--Category 1 (with Group Access: "group A", "group B")

-----Subcategory 1.1 (with Group Access: "group A")

-----Subcategory 1.2 (with Group Access: "group B")

The problem is that a user of "group A" who gets into the page Category 1 will see that there's a Subcategory 1.2. When he clicks on it he gets the "you don't have access" message.
That's not user friendly.

I would like to hide Subcategories names and icons that aren't relevant to the user's group.
(BTW- it's okay at the categories tree at categories block)

I think that it should be something like:

{foreach from=$subcategories item=subcategory}
           {if ($subcategory->checkAccess(intval($cookie->id_customer)))}


on line 28 at category.tpl

Your help will be much appreciated

Link to comment
Share on other sites

This bug has been fixed in v1.3. You'll need to change the getSubCategories function on line 301 of classes/Category.php (in Prestashop v1.2.5) to the following:

public function getSubCategories($id_lang, $active = true)
{
   global $cookie;
   if (!Validate::isBool($active))
       die(Tools::displayError());

   $result = Db::getInstance()->ExecuteS('
   SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description
   FROM `'._DB_PREFIX_.'category` c
   LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.intval($id_lang).')
   LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
   WHERE `id_parent` = '.intval($this->id).'
   '.($active ? 'AND `active` = 1' : '').'
   AND cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
   GROUP BY c.`id_category`
   ORDER BY `name` ASC');

   /* Modify SQL result */
   foreach ($result AS &$row)
   {
       $row['name'] = Category::hideCategoryPosition($row['name']);
       $row['id_image'] = (file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg')) ? intval($row['id_category']) : Language::getIsoById($cookie->id_lang).'-default';
       $row['legend'] = 'no picture';
   }
   return $result;
}

Link to comment
Share on other sites

  • 3 months later...

PrestaShop should already be doing that. What version of PrestaShop are you using? It is the following code on line 111 (in PrestaShop v1.3.1) of modules/blockcategories/blockcategories.php that hides categories that the customer doesn't have access to:

AND cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'

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...