Magento programmatically creates category tree
I want to add a category tree to several options controls
I am looking for a lot on this received this link
but it gives me the output in the ul li structure like this
but I want this tree structure to include multiple options
can anyone know what to do with the changes in the link code
+3
source to share
1 answer
Array preparation:
public function getCategoriesArray() {
$categoriesArray = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSort('path', 'asc')
->load()
->toArray();
$categories = array();
foreach ($categoriesArray as $categoryId => $category) {
if (isset($category['name']) && isset($category['level'])) {
$categories[] = array(
'label' => $category['name'],
'level' =>$category['level'],
'value' => $categoryId
);
}
}
return $categories;
}
Display in the form:
$fieldset->addField('categories', 'multiselect', array(
'label' => $this->__('Categories'),
'name' => 'categories',
'values' => Mage::getModel(...)->getCategoriesArray(),
));
+5
source to share