delete-account-pleas Posted May 29, 2015 Share Posted May 29, 2015 (edited) Hey all, I want to display the category list in my module like presta shop does. Example: 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 May 29, 2015 by Crezzur (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted May 30, 2015 Share Posted May 30, 2015 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'); $tree->setTemplate('tree_associated_categories.tpl') ->setHeaderTemplate('tree_associated_header.tpl') ->setRootCategory($root->id) ->setUseCheckBox(true) ->setUseSearch(true) ->setSelectedCategories($categories); $data->assign(array( '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"> {$category_tree} </div> My 2 cents, pascal. 1 Link to comment Share on other sites More sharing options...
delete-account-pleas Posted May 30, 2015 Author Share Posted May 30, 2015 @PascalVG 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 ? Link to comment Share on other sites More sharing options...
delete-account-pleas Posted May 30, 2015 Author Share Posted May 30, 2015 (edited) i found the following code: Function: 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 May 30, 2015 by Crezzur (see edit history) Link to comment Share on other sites More sharing options...
ovy79ro Posted November 8, 2016 Share Posted November 8, 2016 Hello! 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. array( '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! Link to comment Share on other sites More sharing options...
ovy79ro Posted November 9, 2016 Share Posted November 9, 2016 Found the solution: 'use_checkbox' => true Link to comment Share on other sites More sharing options...
lalitjaa Posted September 12, 2019 Share Posted September 12, 2019 Hi I have to show the category in alphabetical form, for which I am making a module, can you provide me any code to show the category in this type like -: https://prnt.sc/p56j9u Link to comment Share on other sites More sharing options...
zenerry Posted May 9, 2020 Share Posted May 9, 2020 On 5/30/2015 at 10:03 PM, Crezzur said: i found the following code: Function: 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 ? Hello friends, did you find the solution for this problem? Thanks. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted May 11, 2020 Share Posted May 11, 2020 Can you please try this one. $selected_cat = Product::getProductCategoriesFull($id_product, $id_lang); $root = Category::getRootCategory(); $tree = new HelperTreeCategories('kbmp-categories-tree'); $tree->setRootCategory($root->id) ->setInputName('kbmp_allowed_categories') ->setUseCheckBox(true) ->setUseSearch(false) ->setSelectedCategories((array) $selected_cat ); return $tree->render(); 1 Link to comment Share on other sites More sharing options...
zenerry Posted May 11, 2020 Share Posted May 11, 2020 (edited) 4 hours ago, Knowband Plugins said: Can you please try this one. $selected_cat = Product::getProductCategoriesFull($id_product, $id_lang); $root = Category::getRootCategory(); $tree = new HelperTreeCategories('kbmp-categories-tree'); $tree->setRootCategory($root->id) ->setInputName('kbmp_allowed_categories') ->setUseCheckBox(true) ->setUseSearch(false) ->setSelectedCategories((array) $selected_cat ); return $tree->render(); You're really really great man. It works but it brings out this errors, do you know what are they? Notice en línea 138 en archivo C:\\xampp\\htdocs\\PS\\classes\\helper\\HelperTreeCategories.php [8] Array to string conversion Notice en línea 138 en archivo C:\\xampp\\htdocs\\PS\\classes\\helper\\HelperTreeCategories.php [8] Array to string conversion Notice en línea 138 en archivo C:\\xampp\\htdocs\\PS\\classes\\helper\\HelperTreeCategories.php [8] Array to string conversion Warning en línea 142 en archivo C:\\xampp\\htdocs\\PS\\classes\\helper\\HelperTreeCategories.php [2] Illegal offset type Now, I only need to capture the selected value. Could you give me any tip? Thanks for your time. Edited May 11, 2020 by zenerry (see edit history) Link to comment Share on other sites More sharing options...
Minsky_ae Posted August 31, 2020 Share Posted August 31, 2020 (edited) Hello there, I would like to create a custom module where I can display a list of available categories and be able to select multiple ones to then use them on front. I used @ovy79ro code to display the list in back-office but I'll be glad to have some help to go further: 1. List is collapse by default, how can I expand it by default? 2. I used the checkbox property but I've got radio button and can select only one category instead of multiple ones array( 'type' => 'categories', 'label' => $this->l('Product Category'), 'name' => 'FEATURED_CATEGORIES', 'tree' => array( 'id' => 'category', 'selected_categories' => array((int)Configuration::get('category')), ), 'use_checkbox' => true ), 3. I'm not sure how I'm suppose to save the selected categories, how to get selected categories in getConfigFormValues()? protected function postProcess() { $form_values = $this->getConfigFormValues(); foreach (array_keys($form_values) as $key) { Configuration::updateValue($key, Tools::getValue($key)); } } Thanks a lot for any help! Edited August 31, 2020 by Minsky_ae (see edit history) Link to comment Share on other sites More sharing options...
Minsky_ae Posted August 31, 2020 Share Posted August 31, 2020 (edited) I have the answer for question 2, I didn't put the use_checkbox at the right place! 😓 array( 'type' => 'categories', 'label' => $this->l('Featured categories'), 'name' => 'FEATURED_CATEGORIES', 'tree' => array( 'id' => 'category', 'selected_categories' => array((int)Configuration::get('category')), 'use_checkbox' => true ) ), But it still collapse by default and I still don't have any clues on how to save the selected_categories. Edited August 31, 2020 by Minsky_ae Edit code (see edit history) 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