【问题标题】:How know if an attribute in Magento use options如何知道 Magento 中的属性是否使用选项
【发布时间】:2016-01-31 03:49:11
【问题描述】:

我想以编程方式了解 magento 属性是否使用选项或不知道我是否必须显示此选项。

例如 Text 属性不要使用它,而 Dropdown 属性有选项。但是如何以编程方式做出这种区分呢?

【问题讨论】:

    标签: magento magento-1.7 magento-1.9 magento-1.8


    【解决方案1】:
        $product = Mage::getModel('catalog/product')->load($product_id);if($product->hasOptions){
            $optionsArr = $product->getOptions();
            foreach($optionsArr as  $optionKey => $optionVal)
            {
    
                   $options=array();
    
                          foreach($optionVal->getValues() as $valuesKey => $valuesVal)
                            {
    
                                $options[]=array("key"=>$valuesVal->getId(), "val"=>$valuesVal->getTitle());
    
    
                            }
                       $custom_option["titles"][]=array("title"=>$optionVal->getTitle(),"title_id"=>$optionVal->getId(),"options"=>$options);     
    
                            //$optStr.= "</select>";
            }
    

    【讨论】:

      【解决方案2】:
      $attributeCode = 'code_here';
      $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attributeCode);
      if ($attribute->getSourceModel()) {
          //it has options
      } else {
          //it does not have options
      }
      

      【讨论】:

        【解决方案3】:
            $attributeModel = Mage::getModel ( 'eav/entity_attribute' )->loadByCode ( 'catalog_product', 'attribute_code' );
        
                        if ($attributeModel->getData ( 'frontend_input' ) == 'select') {
                            $attribute = Mage::getSingleton ( 'eav/config' )->getAttribute ( 'catalog_product', 'attribute_code' );
                            if ($attribute->usesSource ()) {
                                $options = $attribute->getSource ()->getAllOptions ( false );
                                $ifoptionfound = false;
        
                                if($options)
                                    $ifoptionfound = true;
        
                            }
        
                        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多