首页 > 其他 > 详细

Magento - get Attribute Options of the dropdown type attribute

时间:2014-04-10 14:06:47      阅读:488      评论:0      收藏:0      [点我收藏+]
 

$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["value"];
  echo $option["label"];
}

 

 The above code does not work if the resource_model is empty. The following snippet does the job:

/** @var $attribute Mage_Eav_Model_Entity_Attribute */

$attribute =Mage::getModel(‘eav/entity_attribute‘)->loadByCode(Mage_Catalog_Model_Product::ENTITY,‘YOUR_ATTRIBUTE_CODE‘);

$valuesCollection =Mage::getResourceModel(‘eav/entity_attribute_option_collection‘)->setAttributeFilter($attribute->getId())->setStoreFilter(0,false);

 
// use your own attribute code here $attribute_code = "color"; $attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code); $options = $attribute_details->getSource()->getAllOptions(false); Foreach($options as $option){ // print_r($option) and find all the elements echo $option["value"]; echo $option["label"]; } - See more at: http://www.techdilate.com/code/magento-get-attribute-options-of-the-dropdown-type-attribute/#sthash.7gwBrjQe.dpuf

Magento - get Attribute Options of the dropdown type attribute,布布扣,bubuko.com

Magento - get Attribute Options of the dropdown type attribute

原文:http://www.cnblogs.com/fengliang/p/3653047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!