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()
->addAttributeToSelect('name')
->addAttributeToSelect('description')
->addAttributeToSelect('associated_brand')
->addAttributeToSelect('image')
->setPageSize(12)
->setCurPage(1)
->addAttributeToFilter('level',['gt' => 2])
->addAttributeToFilter('is_active',['eq'=>true])
->addAttributeToFilter(
[
['attribute' => 'name', 'like' => '%'.$searchterm.'%'],
['attribute' => 'description', 'like' => '%'.$searchterm.'%']
]
)->load();
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?