【发布时间】:2013-07-03 16:25:21
【问题描述】:
我有一个管理网格Ultimate_Ressources_Model_Ressource,到目前为止它有两个字段。我想添加一个新的...
但特殊之处在于它已经存在于管理属性中,并且是一个选择字段。
例如,我有一个属性,其代码为color,选择为Red/Green/Blue...我想在我的网格中提出这个字段。
【问题讨论】:
标签: php magento attributes grid magento-1.7
我有一个管理网格Ultimate_Ressources_Model_Ressource,到目前为止它有两个字段。我想添加一个新的...
但特殊之处在于它已经存在于管理属性中,并且是一个选择字段。
例如,我有一个属性,其代码为color,选择为Red/Green/Blue...我想在我的网格中提出这个字段。
【问题讨论】:
标签: php magento attributes grid magento-1.7
要获取属性选项,您可以尝试以下方法:
$attribute = Mage::getModel('eav/config')->getAttribute('product','color');
$options = $attribute->getSource()->getAllOptions();
比在您的网格上添加字段并从上面的代码添加选项。我没有测试,所以你需要自己尝试。
网格列看起来像这样:
$this->addColumn('color', array(
'index' => 'color',
'type' => 'options',
'options' => $options,
));
【讨论】:
谢谢!
我已经这样做了:
$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,
));
【讨论】: