Magento编程:获取所有制造商及其对应的制造商ID列表

4

我需要一些编码方面的帮助。我需要获取所有制造商及其对应的Magento ID列表。这是否可能?请帮忙,谢谢。我尝试了一些模块,但只得到一个或另一个结果。如果可能,请帮我解决最后这个问题。提前感谢您。

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

}

我认为这是另一个问题的扩展:http://stackoverflow.com/questions/10871714/magento-programming-importing-manufacturers-while-checking-for-existing-duplica/ - Drew Hunter
1个回答

13

我不确定你需要的确切格式是什么,但以下示例应说明如何获取所需的值:

$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>";
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接