1

i am trying this code

<?php  
$manufacturerId = 28;
$attributeCode = 'manufacturer';
 $products = Mage::getModel('catalog/product')
                ->getCollection()
                ->addAttributeToFilter($attributeCode, $manufacturerId);

// print all products
echo "<pre>"; print_r($products->getItems()); echo "</pre>";

    ?>

but get real solution

output of this code is

Array
( 
)

how can i get product list by manufacturer name

4 Answers 4

3

Here is one way to do it where you cycle through the options of the attribute and get a product collection for each one:

$name = 'manufacturer';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false);

foreach ($attributeOptions as $_option){
    echo $_option['label'];

    $productcollection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter($name, $_option['value']);

    foreach ($productcollection as $_product){
        echo $_product->getName();
    }
}

This way is a bit slow so you may prefer to instead load a collection of all products and then sort them by the manufacturer attribute.

2
  • it's just give me manufacturer name only i didn't get any product Commented Jan 20, 2015 at 5:41
  • Updated the product collection to include the attributes for use in outputting.
    – Jasuten
    Commented Jan 20, 2015 at 5:45
1

You can Try this:-

 $collection = Mage::getModel('catalog/product')->getCollection();
            $collection->addAttributeToSelect('*');
            $collection->addFieldToFilter(array(array('attribute'=>'manufacturer','eq'=>28),
    ));

// print all products

echo "<pre>"; print_r($collection->getData()); echo "</pre>";
0
$products = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToFilter($attributeCode, $manufacturerId);

In your code Items() did not give the result.

Please use getAllIds() function it give all manufacturer type 28

-1
->addFieldToFilter(array(array('attribute'=>'manufacturer','eq'=>26895)));
1
  • Welcome to SE. Its good to describe the solution you are providing
    – Priyank
    Commented Aug 23, 2017 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.