Reputation: 1800
I am trying to build an array of the active categories on level2.
The problem I have is that the model is returning categories that are no longer active and I do not see a way to filter them.
$storeId = Mage::app()->getStore()->getId();
$category = Mage::getModel('catalog/category')->setStoreId($storeId);
$categoryCollection = $category->getCollection();
$categoryCollectionIds = $categoryCollection->getAllIds();
$level2Categories = array();
foreach($categoryCollectionIds as $categoryId){
$category->load($categoryId);
if($category->getLevel() == '2'){
$level1Categories[$categoryId] = $category->getName();
}
}
echo "<pre>";
print_r($level1Categories);
echo "</pre>";
Any ideas on how to achieve this?
Upvotes: 1
Views: 2233
Reputation: 1040
You can filter your category collection to display active categories using the method addIsActiveFilter()
$categoryCollection = $category->getCollection()->addIsActiveFilter();
Upvotes: 2