addAttributeToFilter Condition is used to Filter the collection query of magento . we can use to to filter the result of category collection, Product Collection, Customer collection, Order collection etc.
When you use this condition into the collection make sure your filterable option should be an attribute not should be a table column or fieldname.
Below is the example to fetch all products and using addAttributeToFilter to filter the result
$collection = Mage::getModel('catalog/product')->getCollection();
Below are all types of condition which you can use To Filter the result
$collection -> addAttributeToFilter('status', array('eq' => 1));
$collection -> addAttributeToFilter('status', array('neq' => 0));
$collection -> addAttributeToFilter('id' , array('in' => array(1,2,3,4)));
$collection -> addAttributeToFilter('id' , array('nin' => array(5,6)));
$collection -> addAttributeToFilter('sku' , array('like' => "%a%"));
$collection -> addAttributeToFilter('sku' , array('nlike' => "test%"));
$collection -> addAttributeToFilter('weight', array('gt' => 10));
$collection -> addAttributeToFilter('weight', array('lt' => 1));
$collection -> addAttributeToFilter('name' , 'notnull');
$collection -> addAttributeToFilter('sort_description' , 'null');
No comments:
Post a Comment