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();
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…