小编use*_*945的帖子

Magento Observer添加命令网格列 - 模糊问题

我已经解决了这个问题,最后!

基本上,我越来越WHERE部分用$where = $select->getPart('where'),然后我经过每一个条件和搜索created_at,如果我觉得有匹配的I替换created_atmain_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 …

join magento magento-1.7

8
推荐指数
1
解决办法
5345
查看次数

标签 统计

join ×1

magento ×1

magento-1.7 ×1