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>";
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?
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');
Hi Mukesh, thank you for the code but where do you put this code? Which file?
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?
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!
Donate
Help this blog grow!
Categories
Archives
Recent Tweets
Recommendations
Find me on Facebook
recent posts
most popular
tag cloud