Here, I will show you how you can filter or fetch products related to any particular attribute and value.
A simple scenario will be filtering products by manufacturer/brand. Suppose, I want to get all products under ‘Samsung’ manufacturer/brand.
For this, you need the attribute code and attribute value ID for which you are fetching products.
Now, lets move on to the code. Here is how you can do this:-
$attributeCode = 'manufacturer' ; |
$products = Mage::getModel( 'catalog/product' ) |
->addAttributeToFilter( $attributeCode , $manufacturerId ); |
echo "<pre>" ; print_r( $products ->getItems()); echo "</pre>" ; |
Hope this helps. Thanks.
No comments:
Post a Comment