【发布时间】:2013-12-11 03:18:06
【问题描述】:
我已使用 /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php 函数 _prepareColumns() 下的以下代码在管理区域的产品网格中添加了一个自定义属性
它工作正常,但现在使用任何搜索过滤器进行搜索时 - 新属性列不显示任何值。
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','custom_column');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeData = $attribute->getData();
$frontEndLabel = $attributeData['frontend_label'];
$attributeOptions = $attribute->getSource()->getAllOptions();
$attributeOptions2 = array();
foreach ($attributeOptions as $value) {
if(!empty($value['value'])) {
$attributeOptions2[$value['value']] = $value['label'];
}
}
$this->addColumn('custom_column',
array(
'header'=> Mage::helper('catalog')->__('Custom Column'),
'width' => '150px',
'index' => 'custom_column',
'type' => 'options',
'options' => $attributeOptions2,
));
在 _prepareCollection() 下我添加了以下代码:
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('custom_column');
我认为这很简单,但我现在没有理解,非常感谢任何帮助!
编辑:
当使用过滤器进行搜索时 - 该列会填充值,除非过滤器是“名称”列。
【问题讨论】:
-
您没有尝试使用目录中的管理属性吗?在那里你可以简单地将“在快速搜索中使用”字段设置为是!
-
试试这个扩展:github.com/tzyganu/GridEnhancer。它是免费的,它允许您在不编写任何代码的情况下管理大量管理网格。
-
@Marius,您的扩展看起来非常好,我检查了源代码并对其进行了测试,但不幸的是它没有解决问题。事实上,我上面的代码在过滤除 Name 列之外的任何列时都会显示值,但您的扩展程序根本没有显示新自定义列的任何值。
-
你解决了这个问题吗?请张贴答案。我有同样的麻烦
标签: php magento filter grid admin