1
$category = Mage::getModel('catalog/category')->getCollection();
            $category->addAttributeToFilter("Top_Menu" , array('eq' => '146'));
            $category->addAttributeToFilter("entity_id" , array('eq' => $catId));
            $category->load();
            $category->getName();

When I use this code i get this error

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat_Collection::getName()

1

A category collection is a collection of category objects.Therefore the category collection has no name. If you would like to get the first category from the category collection you can use the following method.

$category->getFirstItem()->getName();

However it seems like you don't need a collection for what you are trying to achieve. So I'd suggest you just use the loadByAttribute() method. See below

// Load by attribute value
$categoryWithTopMenuId146 = Mage::getModel('catalog/category')->loadByAttribute("Top_Menu","146");

// Get name
$categoryWithTopMenuId1460->getName();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.