Saturday, September 10, 2011

How to get product collection based on attribute (manufacturer, brand) values in magento?

Here is the code to get products based on attribute values. For example here I used to show products based on attribute "brand". In brand attribute I have values nike, adidas. 11 is the code for nike. I here used to display only nike products.
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToFilter('brand', array('in' => array(11)));
$_productCollection->addAttributeToSelect('*');
$_productCollection->load(); 

No comments:

Post a Comment