Magento 在backoffice产品管理中显示值属性而不是id
我在backoffice(下拉列表)的产品管理中添加了一个属性,我想显示该值而不是id 这是解决方案,现在它可以工作了,我更新了:) Grid.phtmlMagento 在backoffice产品管理中显示值属性而不是id,magento,magento-1.9,Magento,Magento 1.9,我在backoffice(下拉列表)的产品管理中添加了一个属性,我想显示该值而不是id 这是解决方案,现在它可以工作了,我更新了:) Grid.phtml protected function _prepareCollection() { ... $collection->addAttributeToSelect('manufacturer'); //my add attribute ... }
protected function _prepareCollection()
{
...
$collection->addAttributeToSelect('manufacturer'); //my add attribute
...
}
protected function _prepareColumns()
{
// add this code
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer');
$options = $attribute->getSource()->getAllOptions(false);
$values = array();
foreach ($options as $option){
$values[$option['value']] = $option['label'];
}
$this->addColumn('manufacturer', //my add attribute
array(
'header'=> 'Manufacturer',
'width' => '100px',
'index' => 'manufacturer',
'type' => 'options',
'options' => $values,
));
查看Mage_Adminhtml_Block_Catalog_Product_Grid::_prepareCollection()有许多addColumn属性 您应该使用可能的值自定义选项索引 有一个伟大的教程中 在简历中,您应该使用以下代码
protected function _getAttributeOptions($attribute_code)
{
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
$options[$option['value']] = $option['label'];
}
return $options;
}
现在,让我们将addColumn函数更新为以下内容:
$this->addColumn('manufacturer', //my add attribute
array(
'header'=> Mage::helper('catalog')->__('Manufacturer'),
'width' => '100px',
'index' => 'manufacturer',
'type' => 'text',
'options' => $this->_getAttributeOptions('attribute_code'),
));
为了获得属性,只需使用
$attribute=Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'manufacturer')代码>
而不是你的 我刚试过,但它不起作用,它仍然显示idi已经找到了解决方案,现在它起作用了,谢谢Rodrigo的帮助