zoukankan      html  css  js  c++  java
  • Magento

     

    $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
    作者:冯亮
             
    能力有限,水平一般。如有错误,欢迎指正
  • 相关阅读:
    【从零开始】【Java】【3】改造成多模块项目
    atomic nonatomic区别
    UIBezierPath
    全局块、栈块、堆块
    动态修改可变数组元素
    layoutSubviews
    约束Constraints
    Objective-C实现一个简单的栈
    NSString 使用 copy、strong
    ARC中__weak;__strong;__unsafe_unretained;修饰词
  • 原文地址:https://www.cnblogs.com/fengliang/p/3653047.html
Copyright © 2011-2022 走看看