So I want to filter a category collection with two attributes. The first attribute attribute_1
must be like a given value. The other attribute may either be like another given value or empty (NULL).
In SQL you would write:
[...] WHERE
(
attribute_1 LIKE '%foo%'
AND
attribute_2 LIKE '%bar%'
)
OR
(
attribute_1 LIKE '%foo%'
AND
attribute_2 is NULL
)
Trying to replicate this in Magento after having investigated how nested filtering should work, I came up with this:
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
array(
array(
array(
'attribute' => 'attribute_1',
'like' => '%foo%'
),
array(
'attribute' => 'attribute_2',
'like' => '%bar%'
),
),
array(
array(
'attribute' => 'attribute_1',
'like' => '%foo%'
),
array(
'attribute' => 'attribute_2',
'null' => true
),
),
)
);
But unfortunately this results in the following error:
PHP Fatal error: Call to a member function getBackend() on boolean in /path/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816 Fatal error: Call to a member function getBackend() on boolean in /path/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816
I'm hoping that anyone here may see my error. Many thanks!