我已经在管理区域中的产品网格中添加了自定义属性,使用以下代码位于 /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');
我觉得这很简单,但我暂时没有理解,非常感谢您的帮助!
编辑:
当使用过滤器进行搜索时,该列会填充值,除非过滤器是名称列。