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

本文介绍如何在Magento中优化订单管理页面,通过增加SKU、数量和客户邮箱等字段,提高后台订单处理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

修改前:


修改后:


#打开
\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一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值