复制到
app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid
,文件中添加以下代码以将账单地址附加到订单网格的
prepareCollection
函数。
$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type = 'billing'");
完整代码是:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type = 'billing'");
$this->setCollection($collection);
return parent::_prepareCollection();
}
然后在_prepareColumns()函数中添加以下代码
$this->addColumn('country_id', array(
'header' => Mage::helper('sales')->__('Country Id'),
'index' => 'country_id',
'filter_index' => 'sales_flat_order_address.country_id',
));
如果想要国家列表,请添加以下代码_preapareCollection()。
$this->addColumn('country_id', array(
'header' => Mage::helper('sales')->__('Country Id'),
'index' => 'country_id',
'type'=> 'options',
'options'=>$this->getAllCountry(),
'filter_index' => 'sales_flat_order_address.country_id',
));
然后在这个文件上添加新的功能。
public function getAllCountry(){
$options = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray();
$countries = array();
foreach($options as $options){
$countries[$options['value']]=$options['label'];
}
return $countries;
}
更多细节请查看
http://bluehorse.in/blog/how-to-add-some-field-or-column--into-magento-order-grid-in-magento-or-customized-magento-order-grid.html。
http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/
$collection->oinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
这是一个打字错误还是你真的漏掉了j
。正确应该是$collection->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
。 - MTM