magento后台的订单列表显示数据过少,而对订单导出的时候,显示的数据和导出的一致。所以为了导出更多订单数据和显示更多数据,就有必要在订单列表调用更多数据。具体效果如下图:
可以看到显示的数据更加丰富,不用再点击到订单详情页进行数据的核对和查看,非常方便。具体修改的文件为:app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php。修改的地方及注意事项:
在_prepareCollection()方法中增加筛选过滤器的条件,同时增加其他表的关联;
增加表关联的时候需要注意join和joinLeft的区别(曾经出现过顶部total的和显示的数据对不上,最后找到问题就在于左右关联这里,建议优先joinLeft);
所有要显示的数据都需要在该方法中读取到,才能在下面输出显示;
_prepareColumns()方法中增加读取的数据显示;
如果需要进行列搜索的话,注意在方法对应的行里面增加filter_index;
需要进行列表排序的话,可以在_prepareCollection()中增加$collection->getSelect()->order(‘entity_id desc’);
最后上代码和文件吧(magento1.9.2):
<?php
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
//hcm add
$collection->getSelect()->joinLeft('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array(
'ShippingAddress'=>new Zend_Db_Expr('CONCAT_WS(", ",sales_flat_order_address.street,sales_flat_order_address.city,sales_flat_order_address.region,sales_flat_order_address.postcode,sales_flat_order_address.country_id,sales_flat_order_address.telephone)'),
'Email' => new Zend_Db_Expr('sales_flat_order_address.email')
) );
$collection->getSelect()->where('sales_flat_order_address.address_type="shipping"');//address_type="shipping"
$orderitemtable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
$collection->getSelect()
->joinLeft(array('sl'=>$orderitemtable)
,"`main_table`.`entity_id`=`sl`.`order_id`",
array(
'sl.name' => new Zend_Db_Expr("group_concat(`sl`.name SEPARATOR ', ')"),
'main_table.created_at' => 'sl.created_at'
)
)
->group("main_table.entity_id");
/*
$collection->getSelect()
->joinLeft('customer_entity','customer_entity.entity_id=main_table.customer_id ',array(
'group_id' => new Zend_Db_Expr("customer_entity.group_id")
))->joinLeft('customer_group','customer_entity.group_id=customer_group.customer_group_id',array(
'group_name' => new Zend_Db_Expr("customer_group.customer_group_code")
)
);
*/
//end
$this->setCollection($collection);
return parent::_prepareCollection();
}
?>
附件下载:Grid