您的位置:首页 > 编程语言 > Qt开发

Magento后台订单列表页,增加SKU、Qty、客户邮箱字段

2015-03-31 11:31 323 查看
注意:这里修改之后分页和总记录数被破坏,还需要进一步优化(如果查询客户邮箱就不会出现这样的问题,目前还没找到解决方案)

修改前:



修改后:



#打开
\app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php
#找到 protected function _prepareCollection()方法,大约57行

添加关联查询:

$collection->getSelect()
->join('customer_entity','main_table.customer_id = customer_entity.entity_id',
array('customer_email' => 'email')) //客户email
->join('sales_flat_order_item','main_table.entity_id = sales_flat_order_item.order_id',
array('qty_ordered' => new Zend_Db_Expr('group_concat( `sales_flat_order_item`.qty_ordered SEPARATOR ", ")'),//Qty
'sku'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ", ")'//SKU
)
));
最后的该方法如下:

protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
//关联查询
$collection->getSelect()->join('customer_entity','main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email'))
->join('sales_flat_order_item','main_table.entity_id = sales_flat_order_item.order_id', array(
'qty_ordered' => new Zend_Db_Expr('group_concat(
`sales_flat_order_item`.qty_ordered SEPARATOR ", ")'),
'sku'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ", ")')
));
//分组
$collection->getSelect()->group('main_table.entity_id');//注意这句不可少
$this->setCollection($collection);
return parent::_prepareCollection();

}
接下来,

#找到 protected function _prepareColumns()方法,大约84行

添加代码如下:

$this->addColumn('sku', array(
'header'    => Mage::helper('catalog')->__('SKU'),
'index'     => 'sku',
'width' => '70px',
'type' => 'text'
));
$this->addColumn('qty', array(
'header' => Mage::helper('sales')->__('Qty'),
'index' => 'qty_ordered',
'width' => '70px'
));
$this->addColumn('Email', array(
'header' => Mage::helper('Sales')->__('Email'),
'width' => '100px',
'index' => 'customer_mail',
'type' => 'text'
));


其他:如果报“1052 Column increment_id in where clause
is ambiguous”错误。注意修改以下代码:

$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type'  => 'text',
'index' => 'increment_id',
'filter_index' =>'main_table.increment_id'//// 这个参数将会解决上述问题
));


如果没有及时看到效果,需要Compilation一下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: