【问题标题】:Magento Programming: Getting list of all Manufacturers and corresponding Manufacturer IDMagento Programming:获取所有制造商的列表和相应的制造商 ID
【发布时间】:2012-06-04 20:35:32
【问题描述】:

我需要一些编码方面的帮助。我需要获取所有制造商及其相应的 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;

}

【问题讨论】:

标签: php magento


【解决方案1】:

不确定您需要的确切格式,但以下示例应该说明如何获取您需要的值:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多