Edge_jr Posted March 4, 2016 Share Posted March 4, 2016 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 More sharing options...
NemoPS Posted March 5, 2016 Share Posted March 5, 2016 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 More sharing options...
Edge_jr Posted March 5, 2016 Author Share Posted March 5, 2016 (edited) 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 March 5, 2016 by edge82 (see edit history) Link to comment Share on other sites More sharing options...
Kambo Posted April 20, 2018 Share Posted April 20, 2018 $root_category_id = Context::getContext()->shop->getCategory(); $category_tree = Category::getNestedCategories($root_category_id, $language_id); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now