Magento编程:获取所有制造商的列表和相应的制造商ID [英] Magento Programming: Getting list of all Manufacturers and corresponding Manufacturer ID

查看:93
本文介绍了Magento编程:获取所有制造商的列表和相应的制造商ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些编码方面的帮助.我需要获取所有制造商的列表及其相应的magento ID.那可能吗?请帮忙.谢谢.我尝试了一些mod,但只能得到其中一个.如果可能的话,请帮忙.我先谢谢你

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;

}

推荐答案

不确定要使用哪种格式,但是下面的示例应说明如何获取所需的值:

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

这篇关于Magento编程:获取所有制造商的列表和相应的制造商ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆