Posted By

dmistriotis on 08/17/10


Tagged

magento


Versions (?)

Retrieve products with a specific attribute value


 / Published in: PHP
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.