I'm using the following to filter my collection:
$collection = Mage::getModel('catalog/product') ->getCollection() ->setStoreId($storeId) ->addAttributeToSelect('sepdate') ->addStoreFilter($storeId) ->addAttributeToFilter('status', array('eq' => 1)) ->addAttributeToFilter('sepdate', array('eq' => 'Yes')) ->getAllIds();
The attribute 'sepdate' is a yes/no attribute and it is added to the product list eav.
My problem is that the above doesn't work. When removing the:
->addAttributeToFilter('sepdate', array('eq' => 'Yes'))
The collection works fine, but when that is added nothing gets selected.
I have checked that there actually are products with the attribute set for 'Yes' and I have also tested with 1 instead of 'Yes'.
Can anyone help me with what i'm doing wrong here?
Okay, looked at the sql it made and think I found the culprit. The sql looks like this:
SELECT `e`.*, `at_sepdate`.`value` AS `sepdate` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_entity_int` AS `at_sepdate` ON (`at_sepdate`.`entity_id` = `e`.`entity_id`) AND (`at_sepdate`.`attribute_id` = '144') AND (`at_sepdate`.`store_id` = 0) INNER JOIN `catalog_product_website` AS `product_website` ON product_website.product_id = e.entity_id AND product_website.website_id = '1' WHERE (at_sepdate.value = 1)
Where this is causing the trouble:
AND (`at_sepdate`.`store_id` = 0)
The store_id should be 1 and I can't quite understand why it isn't since i'm setting both setStoreID() and addStoreFilter(). ?