In front-end I am displaying all category of first level.
Now I want to check Is there any category either available or not in first level.
I am using this code and getting all categories.
public function getCategory()
{
$parentCategoryId = Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')
->getCollection()
->addFieldToFilter('parent_id', array('eq'=>$parentCategoryId))
->addFieldToFilter('is_active', array('eq'=>'1'))
->addAttributeToFilter('level', 2)
->addAttributeToSelect('*');
return $categories;
}
If there is no category available then I want to display a message but I don't know how to check category is available or not in first level.
To check if the category exists at the first level
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')//or you can just add some attributes
->addAttributeToFilter('level', 2)//2 is actually the first level
->addAttributeToFilter('is_active', 1)//if you want only active categories
;
if(isset($categories) && !empty($categories->getData())) {
echo "Category found";
} else {
echo "Category not found";
}