14Jul/105
Filter Magento product collection using addAttributeToFilter() to create SQL OR(s)
/** Add attribute filter to collection
*
* If $attribute is an array will add OR condition with following format:
* array(
* array('attribute'=>'firstname', 'like'=>'test%'),
* array('attribute'=>'lastname', 'like'=>'test%'),
* )
*/
// Correct application looks like this
$_productCollection->addAttributeToFilter(
array(
array('attribute'=>'name', 'like'=>'%productname%'),
array('attribute'=>'sku', 'like'=>'%productsku%')
)
);



July 27th, 2010 - 02:44
Is it possible to filter products based on the website they’re assigned to? Is there some documentation available somewhere that lists which attributes are available for filtering?
July 28th, 2010 - 13:03
We will be writing a separate post in the next day or two to provide a complete answer to your question.
Thanks!
Jason D.
December 14th, 2010 - 18:49
ItÅ› works !!
May 13th, 2011 - 04:34
aaa i’got a problem,
i’ve got 1 instead of having the name of my field but it seems to work.
for example:
“SELECT `main_table`.* FROM `amer_program_code` AS `main_table` WHERE (((1 = ’8′) or (1 = ’8′)))”
May 17th, 2011 - 08:19
benjion,
Please take a look at your code again and make sure it is exactly as we have it. It is important that you keep the arrays exactly as shown. I noticed that you have too many parentheses around your WHERE clause. I’m going out on a limb here but the 1 could come from a missing key in the array, e.g.
array('attribute', 'eq' => '8')or something similar. It should bearray('attribute' => 'name', 'eq' => '8').I made some tests on my development system and this does NOT work properly for me.
Perhaps if you show us the code, we can figure out what is going wrong here.