我已经解决了这个问题,最后!
基本上,我越来越WHERE部分用$where = $select->getPart('where')
,然后我经过每一个条件和搜索created_at
,如果我觉得有匹配的I替换created_at
用main_table.created_at
.
我已经对此进行了测试,一切正常,如果有什么东西可以"越野车"请告诉我.
谢谢大家!!
public function salesOrderGridCollectionLoadBefore($observer)
{
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->joinLeft(array('custab' => 'my_custom_table'), 'main_table.entity_id = custab.order_id',array('custab.field_to_show_in_grid'));
if ($where = $select->getPart('where')) {
foreach ($where as $key=> $condition) {
if (strpos($condition, 'created_at')) {
$new_condition = str_replace("created_at", "main_table.created_at", $condition);
$where[$key] = $new_condition;
}
}
$select->setPart('where', $where);
}
Run Code Online (Sandbox Code Playgroud)
}
我正在尝试使用observer从自定义表中添加销售订单网格中的新列.一切正常,直到我尝试使用列过滤网格created_at
.
问题是因为我created_at
在自定义表和sales_flat_order_grid
表中有相同的列名().
我收到了这个错误
SQLSTATE [23000]:完整性约束违规:1052 where子句中的'created_at'列不明确
如果我将此行编辑'index' => 'created_at'
为
'index' => '**main_table**.created_at'
,in …