2012-06-04 45 views
3

我需要一些編碼方面的幫助。我需要獲得所有制造商與他們相應的magento ID列表。那可能嗎?請幫忙。謝謝。我嘗試了一些mods,但只得到一個或另一個。如果可能的話,請幫助這最後一件事。我感謝你提前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; 

} 
+0

我覺得這是一個擴展到另一個問題:http://stackoverflow.com/questions/10871714/magento-programming-importing-manufacturers-while-checking-for-existing-duplica/ –

回答

10

不知道到底是什麼格式,你需要這樣的,但下面的例子應該說明如何得到你所需要的值:

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