我在Magento 1.7.0.0中的订单网格中添加自定义列时出现此问题,我希望您能够在这里给我一个帮助.基本上我遵循了这个指南http://www.atwix.com/magento/customize-orders-grid/,它解释了我必须制作一个本地版本/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php并进行一些更改以获得我想要的额外列.通过遵循上述指南,它说我必须编辑函数_prepareCollection()来添加这一行(指定我想在数组中提取的字段)
$collection->getSelect()->join('magento_sales_flat_order_address', 'main_table.entity_id = magento_sales_flat_order_address.parent_id',array('telephone', 'email'));
Run Code Online (Sandbox Code Playgroud)
之前
return parent::_prepareCollection();
Run Code Online (Sandbox Code Playgroud)
并添加两列_prepareColumns()如下:
$this->addColumn('telephone', array(
'header' => Mage::helper('sales')->__('Telephone'),
'index' => 'telephone',
));
$this->addColumn('email', array(
'header' => Mage::helper('sales')->__('Email'),
'index' => 'email',
));
Run Code Online (Sandbox Code Playgroud)
这就是它,显然......或者可能不是,因为当我这样做时会抛出以下错误:
Item (Mage_Sales_Model_Order) with the same id "XXXX" already exist
Run Code Online (Sandbox Code Playgroud)
根据下面的评论,解决方案是在_prepareCollection之前添加以下行$this->setCollection($collection):
$collection->getSelect()->group('main_table.entity_id');
Run Code Online (Sandbox Code Playgroud)
添加该行后,订单网格现在显示电子邮件和电话列,就像我想要的那样,但结果显示分页停止工作,它只显示最近的20,它显示"第1页中的1","2条记录发现"在上面.我似乎无法弄清楚为什么会发生这种情况,我看到的每一条评论都不会超出上面的最后一条指令.可能是这个问题的原因是什么?
我认为它可以复制,因为我没有对此模型进行任何其他修改.