获取 magento 属性下拉值


Get magento attribute dropdown value

如何从下拉列表中获取 magento 属性值:yesno选项和多值下拉列表?

据我所知 - 单个文本将通过以下方式获得值:

<?php $designer = Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('brands'); ?>

谢谢。

你可以这样做:

...
$attrCode = 'color';
$storeid = Mage::app()->getStore()->getStoreId();
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attrCode);
$attr_id = $attribute->getId();
$values = array();
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
    ->setAttributeFilter($attr_id)
    ->setStoreFilter($storeid, false)
    ->load();
foreach ($valuesCollection as $item) {
    $values[$item->getId()] = $item->getValue();
}
var_dump($values); // prints that attribute values as array
...

希望对您有所帮助。

你需要编写这样的代码:

  $attribute_code = "color"; 
  $attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code); 
  $options = $attribute_details->getSource()->getAllOptions(false); 
  foreach($options as $option){ 
   echo $option["label"];
  }