如何将发货日期添加到管理销售订单网格

时间:2014-12-05 11:53:25

标签: magento admin

我很难将新列(发货日期)添加到销售订单管理网格。我将文件Grid.phpapp/code/core/Mage/Adminhtml/Block/Sales/Order复制到app/code/local/Mage/Adminhtml/Block/Sales/Order,并在_prepareCollection()函数中添加了代码

$collection->getSelect()->joinLeft('sales_flat_shipment_grid','sales_flat_shipment_grid.order_id=main_table.entity_id',array('shipped_date' => 'sales_flat_shipment_grid.created_at'));

并在_prepareColumns()添加了此

$this->addColumn('shipped_date', array(
      'header'    => Mage::helper('sales')->__('Shipped Date'),
      'index'     => 'shipped_date',
      'type'      => 'datetime',
      'filter_index'=>'sales_flat_shipment_grid.created_at',
));

我的问题是,当有多个货件的订单时,当我转到销售订单网格时,我收到错误There has been an error processing your request,表示存在重复的订单ID。 如果订单没有多个货件,那么销售订单网格就可以了,并显示相应订单的发货日期。

有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

如评论中所述,您需要按entity_id对结果进行分组:

$collection
->getSelect()
->joinLeft('sales_flat_shipment_grid',
    'sales_flat_shipment_grid.order_id=main_table.entity_id', 
    array('shipped_date' => 'MAX(sales_flat_shipment_grid.created_at)') // Since you want the most recent one
);

$collection->getSelect()->group('main_table.entity_id');

无法测试它,但类似的东西应该有效。

此致 哈维尔