Home » Magento

Magento: Get list of all manufacturers

7 January 2010 1,359 views 5 Comments Popularity: 15% Share/Bookmark

Here is the code to list all the manufacturers.

$_product = $this->getProduct();

$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
                  ->setEntityTypeFilter($_product->getResource()->getTypeId())
                  ->addFieldToFilter('attribute_code', 'manufacturer');

$attribute = $attributes->getFirstItem()->setEntity($_product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);

echo "<pre>"; print_r($manufacturers); echo "</pre>";

From Mukesh Chapagain's Blog | Post Magento: Get list of all manufacturers

Related posts:

  1. Magento: How to get attribute name and value?
  2. Magento: Remove list or grid mode as display option
  3. Magento: How to delete System Attribute?
  4. Magento: Get manufacturer name and id from product
  5. Magento: Adding category attributes

5 Comments »

  • Paul said:

    a while back i deleted the ‘Manufacturer’ attribute and created a new one and now this code isn’t working for me. Is there a fix so that it will pull the data from the newer attribute?

  • Mukesh (author) said:

    Just put your new attribute code in addFieldToFilter. See the code below:-

    $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setEntityTypeFilter($_product->getResource()->getTypeId())
    ->addFieldToFilter('attribute_code', 'YOUR_NEW_ATTRIBUTE_CODE');

  • Karlo said:

    Hi Mukesh, thank you for the code but where do you put this code? Which file?

  • Jeff said:

    When l put this into my 1column.phtml l get this error:

    Fatal error: Call to a member function getResource() on a non-object in /var/www/magento/app/design/frontend/default/bookstore/template/page/1column.phtml on line 183

    Can anyone help?

  • Augusto Leao said:

    This works:

    $collection = Mage::getResourceModel(‘catalog/product_attribute_collection’) ->addFieldToFilter(‘attribute_code’, array(‘eq’=>’manufacturer’))
    ->addStoreLabel(Mage::app()->getStore()->getId())
    ->load();

    foreach($collection as $a){
    $manufArray = $a->getSource()->getAllOptions(false);
    foreach($a->getSource()->getAllOptions(false) as $option)
    $manufArray[$option['value']] = $option['label'];
    }

    //IF YOU NEED TO DEBUG YOUR VALUES
    print_r($manufArray);

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.