Magento Sales Grid Filter bug

目录

当你使用Sales Order的filter时有时会莫名其妙的出现img就会出现下面Magento经典的报错页面。img在var/report/找到这个报告,显示

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ordercomment' in 'where clause'
你的错误可能会是下面这样子的:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'create_at' in 'where clause'
更可能会是这个: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'where clause'
从core复制文件app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php到app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php.。
找到create_at,这一栏的addColumn函数

$this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Purchased On'),
            'index' => 'created_at',
            'type' => 'datetime',
            'width' => '100px',
 ));

添加filter_index属性,给表字段添加mian_table。这样filter就能找到对应的表了,一般这种情况是安装了一些插件,重写sales_resource下的order_grid_collection这个类,导致filter会找不到对应的字段。当然,造成这个bug是因为我安装了Magemaven OrderComment这个插件。

$this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Purchased On'),
            'index' => 'created_at',
            'type' => 'datetime',
            'width' => '100px',
            'filter_index' => 'main_table.created_at'
        ));

// Add order comment to grid
        $this->addColumn('ordercomment', array(
            'header' => Mage::helper('ordercomment')->__('Order Comment'),
            'index' => 'ordercomment',
            'filter_index' => 'ordercomment_table.comment',
        ));

以上代码在Magento CE 1.6.2 测试通过。

参考

  1. How to extend Magento Order Grid