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');
  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. ));
  11. foreach ($collection as $product) {
  12. //var_dump($product);
  13. var_dump($product->getData());
  14. }


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.