I think I tried everything and read everything, but I’m pretty confused about filtering product collection in Magento. I created a new product attribute ‘syncron_state’, but I can’t manage to filter the product_collection by this filter. When I try to filter by core attributes it works and that’s clear.
$productsCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('sku', array('eq' => '000001'))
->setCurPage(1)->setPageSize(10)
->load();
But if I try to filter by my attribute I get nothing.
$productsCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('syncron_state', array('eq' => '1'))
->setCurPage(1)->setPageSize(10)
->load();
The syncron_state is a Yes/No Attribute, as far as I know it has an integer value in database (but i tried true/false and yes/no in filtering also).
I tried all versions of addAttributeToFilter and AddFieldToFilter.
Oh, and I’m fighting with Magento 1.7.0.0
Your collection using
syncron_stateas a filter should work as expected, at least for products havingsyncron_stateset toyes.One possible reason for not getting products would be, that you failed to add the new
syncron_stateattribute to the proper attribute set (which is a must).Another possible reason would be, that you simply forgot to set the
syncron_stateattribute of at least one product toYes.