What's the difference between addAttributeToFilter and addFieldToFilter in Magento? I created a custom attribute YES/NO. But neither of them is working for me when I tried to pull a product collection. Its not filtering anything.
$Products = Mage::getModel('catalog/product')->getCollection();
$Products->addAttributeToSelect('*');
$Products->addFieldToFilter('amazon_listed',1);
$Products->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$Products->load();
addFieldToFilter will filter the products based on columns in the database from the table catalog_product_entity.
addAttributeToFilter will filter the products based on the attributes that you've included in your collection.
In your case you must use addAttributeToFilter like this:
$Products->addAttributeToFilter('amazon_listed',array('eq' => 1));
$Products->addAttributeToFilter('status',array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With