【问题标题】:Magento 1.7 - How to add an attribute (choice list that ever exist in manage attributes) in a new admin gridMagento 1.7 - 如何在新的管理网格中添加属性(管理属性中存在的选择列表)
【发布时间】:2013-07-03 16:25:21
【问题描述】:

我有一个管理网格Ultimate_Ressources_Model_Ressource,到目前为止它有两个字段。我想添加一个新的... 但特殊之处在于它已经存在于管理属性中,并且是一个选择字段。
例如,我有一个属性,其代码为color,选择为Red/Green/Blue...我想在我的网格中提出这个字段。

【问题讨论】:

    标签: php magento attributes grid magento-1.7


    【解决方案1】:

    要获取属性选项,您可以尝试以下方法:

    $attribute = Mage::getModel('eav/config')->getAttribute('product','color');
    $options = $attribute->getSource()->getAllOptions();
    

    比在您的网格上添加字段并从上面的代码添加选项。我没有测试,所以你需要自己尝试。

    网格列看起来像这样:

    $this->addColumn('color', array(
        'index'     => 'color',
        'type'      => 'options',
        'options'   => $options,
    ));
    

    【讨论】:

      【解决方案2】:

      谢谢!

      我已经这样做了:

      $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'color');
      if ($attribute->usesSource()) {
      $options = $attribute->getSource()->getAllOptions(false);
      }
      $fieldset->addField('color', 'select', array(
      'name'       => 'color',
      'label'      => Mage::helper('ressources')->__('My color'),
      'title'      => 'title_here',
      'values'     => $options,
      ));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-10
        相关资源
        最近更新 更多