Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Programming: Getting list of all Manufacturers and corresponding Manufacturer ID

Tags:

php

magento

I need help with some coding. I need to get a list of All Manufacturers with their corresponding magento ID. Is that possible? Please help. thanks. I tried some mods but only get one or the other. If its possible, pls help w/ this one last thing. I thank you in advance

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer');

foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
     $attributeArray[$option['value']] = $option['label'];
     }  

foreach($attributeArray as $key=>$val){
echo $val;

}
like image 234
user1433709 Avatar asked Dec 12 '22 01:12

user1433709


1 Answers

Not sure exactly what format you require this in but the following example should illustrate how to get to the values you need:

$attribute = Mage::getModel('eav/entity_attribute')
                ->loadByCode('catalog_product', 'manufacturer');

$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter($attribute->getData('attribute_id'))
            ->setStoreFilter(0, false);

$preparedManufacturers = array();            
foreach($valuesCollection as $value) {
    $preparedManufacturers[$value->getOptionId()] = $value->getValue();
}   


if (count($preparedManufacturers)) {
    echo "<h2>Manufacturers</h2><ul>";
    foreach($preparedManufacturers as $optionId => $value) {
        echo "<li>" . $value . " - (" . $optionId . ")</li>";
    }
    echo "</ul>";
}
like image 51
Drew Hunter Avatar answered May 12 '23 04:05

Drew Hunter