Get categories by id
-
12-12-2019 - |
Question
I'd like to retrive the categories tree excluding some categories of level 2. Here is my code where I exclude them
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('is_active')
->addAttributeToFilter('level', array('eq'=>2))
->addAttributeToFilter('entity_id',array('nin'=>array($parent_id_to_exclude)))
->load()
;
Then I imagine to create a foreach loop to retrieve the subcategories, but I have no idea which is the attribute to select the parents. thanks
Solution
You can get child items by filtering on parent_id
. Optionally there is a resource model Mage_Catalog_Model_Resource_Category_Tree
that accepts a collection via method addCollectionData
.
I've never used it to be honest but might help with building the category tree
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange