en Jump to content
  • 0

Call category list in custom module


Hey all,


I want to display the category list in my module like presta shop does.





After searching i have found the code to call the menu should be in the function getParentsCategories();

But I'm not able to call the list like i marked above.


Code i tried:

// Define id_category
$id_category = $this->category->id;

// Initialize object Category
$category = new Category((int)$id_category);

// Get array parent from the initialized object Category
$array_parent = $category->getParentsCategories();

So i need the php code to display the category menu in my module.


Thanks in advance!

Edited by Crezzur

Share this post

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

With getParentsCategories, you only get the direct parents of a specific category, which is one branch of the tree. I expect you want the whole tree, so maybe better use the code they use in back office, catalog->products->edit product (associations tab)


from controllers/admin/AdminProductsController.php



$tree = new HelperTreeCategories('associated-categories-tree', 'Associated categories');
    'category_tree' => $tree->render()


For full use how to implement it, look in the file.





and then in your tpl file something like:


<div id="category_block">
My 2 cents,

Share this post

Link to post
Share on other sites
  • 0



Indeed i looked at the wrong function


i do not use a .tpl file for this part of back-office so i tried to put it into a variable which results in nothing.


using the following code in my datasheetpro.php also results in a empty variable.

$helper = new HelperTreeCategories('categories-treeview');
$category_tree = $helper->render();

echo 'TEST: '.$category_tree;

any idea ?

Share this post

Link to post
Share on other sites
  • 0

i found the following code:



public static function getCategoryTree($id_product,$id_lang){
	$root = Category::getRootCategory();
	$selected_cat = Product::getProductCategoriesFull($id_product, $id_lang);
	$tab_root = array('id_category' => $root->id, 'name' => $root->name);
	$helper = new Helper();
	$category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true);
	return $category_tree;
$id_test = Configuration::get('PS_ROOT_CATEGORY');
$txt .= '<div> TEST: '.$this->getCategoryTree($id_test, $id_lang).' </div>

This gives me this as result:



but not a full tree for some reason ?

Edited by Crezzur

Share this post

Link to post
Share on other sites
  • 0



Sorry for reopening this thread. I try to list category tree list, I use the code below, but this code list with radio buttons, and i need checkbox buttons, like in picture from first post. I dont want to use any .tpl file.


           'type'  => 'categories',
           'label' => $this->l('Product Category'),
           'desc'    => $this->l('Product Category.'),  
           'name'  => 'category',
           'tree'  => array(
                'id' => 'category',
                'selected_categories' => array((int)Configuration::get('category')),


Does anyone know how to do that?

Thank you!

Share this post

Link to post
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


Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More