Jump to content

Get All Subcategories Of Category


Edge_jr

Recommended Posts

Hi,

 

I want to get all sub categories of given category.

 

Following code gives only subcategory having id_parent from ps_category table.

 

$subcatObj = new Category("6");
$subcatObj2 = $subcatObj->getSubCategories($this->context->language->id);


echo"<pre>";
print_r($subcatObj2);
echo"</pre>";

My category has tree like category1=>category2=>category3=>category4

 

Therefore category4 parent is category 1,2 and 3

 

Any idea?

 

-Thanks

 

Link to comment
Share on other sites

You can use getAllChildren instead, it will get all of the children in the tree. However, you will have to sort them and properly build the tree afterwards.
Otherwise you can just use a recursive function with getSubcategories (if there are results, getSubcategories again, etc)

Link to comment
Share on other sites

Hi,

 

Could you please give example use of getAllChildren function or any file in prestashop using it.

 

I think modules/blocktopmenu using to show in menu.

 




$children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop);



 

This function gives only direct subcategories of category not sub sub categories of subcategories.

 

-Thanks

Edited by edge82 (see edit history)
Link to comment
Share on other sites

  • 2 years later...

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