addAttributeToFilter is one of the main function of the Magento from which specific product collection can be called from the database using queries only. You can use write the queries as per the need and result will be then found accordingly. Here is example of addAttributeToFilter Conditions In Magento.
$products = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('name', array('like' => 'A%')) ->load();
The above code will fetch a product collection, with each product having it’s name, url, price and image loaded in as per the data array. Here we have used the condition like as A% which will fetch the product names starting from the A respectively. There are similar many conditions operator that used in addition with addAttributeToFilter Conditions In Magento.
Magento addAttributeToFilter with conditions of greater than, less than, greater than and equal to, less than and equal to, not equal, like, not like, is not null, is null, equal to. are shown below with code that you can alter to make specific changes as required in your code.
$products = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'small_image', 'status')) ->addAttributeToFilter('status', array('eq' => 1)) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('sku', array('neq' => 'test-product')) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('name', array('like' => 'A%')) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('name', array('nlike' => 'A%')) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('in' => array(15,30,50))) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('nin' => array(15,30,50))) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('desc', 'null')//true ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('desc', 'notnull')//true ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('gt' => 20)) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('lt' => 20)) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('gteq' => 10)) ->load();
$products = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect(array('name', 'product_url', 'sku','small_image')) ->addAttributeToFilter('id', array('lteq' => 10)) ->load();
Toys have always played a crucial role in childhood, fueling imagination, creativity, and learning. Whether you're looking for educational playsets,…
Toys are an essential part of childhood, shaping creativity, learning, and fun-filled memories. Whether it’s the soft embrace of plush…
Toys are a gateway to imagination, creativity, and learning. Whether it’s a child’s first plush toy, a set of engaging…
Toys are more than just playthings; they help children explore, learn, and develop essential life skills. From interactive sensory toys…
Toys are more than just playthings; they are tools that foster creativity, motor skills, and cognitive development in children. From…
Toys play an integral role in a child’s growth and development. They spark creativity, encourage learning, and provide endless hours…