Jump to content

[solved] Category info - how to get category parents ID ?


Recommended Posts

Hi

in my shop I have 4 levels of depth of the categories.

 

When you are in a category of level 4 I would like to know who is the category of Level 2

The parameter id_parent know the higher category, but how do I know that the level 2?

I have to use this information in the file category.tpl

 

thanks

Link to comment
Share on other sites

You mean you want to display the grandfather of category level 4?

 

Thanks for the replay

 

I have this structure

 

- category one
---->sub-category alpha
=====>sub sub-category beta
- category two
- category Three
- category four

 

when I'm in the sub-category alpha, I know the information of the category one through parameter id_parent.

When you are in the sub sub-category beta, how do I know the information of the category one?

Link to comment
Share on other sites

I would go for a module, and use this query

 

'SELECT id_parent from ps_category WHERE id_category = ' . $current_id_parent

 

Where of course the variable is the $id_parent of the current category. You should create a new hook in the category, this way

http://nemops.com/adding-hooks-to-prestashop-1-5/

 

Then you can either pass a variable to the hook, or grab the current category id like $id_category = Tools::getValue('id_category');

Of course, to get the parent use $category = new Category($id_category) and then $category->parent

Link to comment
Share on other sites

×
×
  • Create New...