Retrieve products with a specific attribute value


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. $collection = Mage::getModel('catalog/product')->getCollection();
  2. $collection->addAttributeToSelect('name');
  3. $collection->addAttributeToSelect('orig_price');
  4.  
  5. //filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B
  6. $collection->addFieldToFilter(array(
  7. array('name'=>'orig_price','eq'=>'Widget A'),
  8. array('name'=>'orig_price','eq'=>'Widget B'),
  9. ));
  10.  
  11. foreach ($collection as $product) {
  12. //var_dump($product);
  13. var_dump($product->getData());
  14. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.