I'm filtering a product collection by the custom attribute ean
with the following code
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('ean');
$collection->addFieldToFilter('ean', '678678');
foreach ($collection as $product)
{
Mage::Log('product found');
}
There is product with this ean but no product is found.
Best Answer
The methods
addFieldToFilter()
andaddAttributeToFilter()
are the same.I would try to remove the filter, then loop over the collection and check the values of ean. What query is fired?
Maybe some observer hooks into
catalog_product_collection_load_before
and the query is altered and filters are added?Load the collection and then check
echo (string)$collection->getSelect()
. After(!) the->load()
.