I have some code to perform a basic search of categories. It works by searching the category name and description - attributes that are both core.

The code I have is as follows:

$_categories = Mage::getModel('catalog/category')->getCollection()  
    ->addAttributeToFilter('level',['gt' => 2])
            ['attribute' => 'name', 'like' => '%'.$searchterm.'%'],
            ['attribute' => 'description', 'like' => '%'.$searchterm.'%']

Prior to enabling the flat catalog for categories, it returned the expected results - any categories that had a match for the search term in their name or description.

With the flat catalog enabled, the name or description search does not work. If I output the underlying collection query, it is as follows:

SELECT `main_table`.`entity_id`, `main_table`.`level`, `main_table`.`path`, `main_table`.`position`, `main_table`.`is_active`, `main_table`.`is_anchor`, `main_table`.`name`, `main_table`.`description`, `main_table`.`associated_brand`, `main_table`.`image` 
FROM `catalog_category_flat_store_1` AS `main_table` 
WHERE (level > 2) AND (is_active = '1')

As can be seen from the above, the name and description clause are missing completely.

I've checked the generated catalog_category_flat_store_1 table and the fields are present there.

Any ideas why Magento is dropping these filters from the query, only when using the flat catalog?

1 Answer 1


In \Mage_Catalog_Model_Resource_Category_Flat_Collection::addAttributeToFilter

public function addAttributeToFilter($attribute, $condition = null)
    if (!is_string($attribute) || $condition === null) {
        return $this;

    return $this->addFieldToFilter($attribute, $condition);

It seems not possible to have an array in first parameter. You need to get the Select object and do your query manually when flat is enabled.

Hope this help,

  • So this is just another example where flat catalog implementation is not interface compatible with standard EAV implementation?
    – BrynJ
    Commented Nov 30, 2015 at 17:20
  • unfortunately yes. This is a big problem in Category. When I start a project I usually start using flat or EAV but never change in project life cycle.
    – bchatard
    Commented Nov 30, 2015 at 18:19
  • What if you use addFieldToFilter() directly instead? I don't see a reason why it should not work Commented Dec 13, 2015 at 10:37
  • Yes it will work, only if you always use flat (doesn't works on EAV)
    – bchatard
    Commented Dec 14, 2015 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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