Sev*_*res 2 magento magento-1.7
我在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条记录发现"在上面.我似乎无法弄清楚为什么会发生这种情况,我看到的每一条评论都不会超出上面的最后一条指令.可能是这个问题的原因是什么?
我认为它可以复制,因为我没有对此模型进行任何其他修改.
好吧,解决了.这就是我所做的:受到这个答案的启发/sf/answers/295357051/,我制作了该文件的副本lib/Varien/Data/Collection/Db.php,将其放置app/core/local/Varien/Data/Collection/Db.php并复制了该答案上建议的修改以修复组选择计数错误这给了我上面的问题.到目前为止它似乎工作.
然而,行中存在问题,当我点击订单时它说订单"不再存在",所以我检查了实际网址并且结果显示网址中的order_id与"entity_id"中的相同order_address表,它与订单的实际关联ID(parent_id)不对应.调整了很长时间与MySQL查询后,我意识到这个问题是由调用的函数_prepareColumns()和getRowUrl()函数在/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php做我,因为他们获取了错误的标识.所以我做了以下更改:
在_prepareColumns()与Action列对应的代码中,我将'getter'更改为'getParentId',如下所示:
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
$this->addColumn('action',
array(
'header' => Mage::helper('sales')->__('Action'),
'width' => '50px',
'type' => 'action',
//~ 'getter' => 'getId',
'getter' => 'getParentId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('View'),
'url' => array('base'=>'*/sales_order/view'),
'field' => 'order_id',
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
}
Run Code Online (Sandbox Code Playgroud)
在getRowUrl()函数中,我更改了函数中的$ row语句,getUrl()如下所示:
public function getRowUrl($row)
{
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
//~ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
return $this->getUrl('*/sales_order/view', array('order_id' => $row->getParentId()));
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
而现在它就像一个魅力.我希望这有助于其他人.