Return to Snippet

Revision: 30575
at August 17, 2010 20:09 by dmistriotis


Initial Code
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('name');      
$collection->addAttributeToSelect('orig_price');        

//filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B
$collection->addFieldToFilter(array(
        array('name'=>'orig_price','eq'=>'Widget A'),
        array('name'=>'orig_price','eq'=>'Widget B'),           
));

foreach ($collection as $product) {
        //var_dump($product);
        var_dump($product->getData());
}

Initial URL
http://stackoverflow.com/questions/1332742/magento-retrieve-products-with-a-specific-attribute-value

Initial Description
Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model

Initial Title
Retrieve products with a specific attribute value

Initial Tags
magento

Initial Language
PHP