Home » Magento7 January 2010

Magento: Get list of all manufacturers

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

php magento mukesh chapagain

Get New Post by Email

Find me on

Facebook Twitter Google+ LinkedIn RSS Feed
  • http://www.redmousecomputers.com Paul

    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?

  • http://blog.chapagain.com.np Mukesh

    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

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

  • Jeff

    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?

  • http://bulbamerica.com Augusto Leao

    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);

  • http://www.bluehorse.in shawkat alam

    i want to edit the manufacturer list in product information page. i added the a manufacturer name in user. Now i want to show only that manufacturer name in product information page.

    i think tabs.php under app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit helps to bring the general tab and the information on it.

    i think this block of code helps to bring the general tab and the information on it in product information page.

    if (count($attributes)==0) {
    continue;
    }

    $this->addTab(‘group_’.$group->getId(), array(
    ‘label’ => Mage::helper(‘catalog’)->__($group->getAttributeGroupName()),
    ‘content’ => $this->getLayout()->createBlock($this->getAttributeTabBlock())
    ->setGroup($group)
    ->setGroupAttributes($attributes)
    ->toHtml(),
    ));

    please help me if i want to add or remove manufacturer in product information page with code without changing the attribute information.

  • Mubashar Crewlogix

    It is not workable. It is giving error.