2013-01-21 56 views
2

我試圖讓訂單網格顯示客戶的郵政編碼/郵政編碼。Magento - 將郵政編碼/郵政編碼添加到Magento 1.6.2中的訂單網格中

我想加入sales_flat_order_aldress別名與集合,但沒有成功。

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('postcode')); 
    //var_dump($collection); 
    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 

任何人都可以幫我找出解決方案。

回答

2

在返回parent :: _ prepareCollection()之前;您應該創建一個連接:

$collection->getSelect()->joinLeft(array('billing'=>'sales_flat_order_address'), 
    'main_table.entity_id = billing.parent_id AND billing.address_type="billing"',array('billing.postcode AS bp')); 

如果你想航運郵編而是使用:

$collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'), 
    'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp')); 

而且在方法_prepareColumns粘貼:

$this->addColumn('bp', array(
     'header' => Mage::helper('sales')->__('Billing Postcode'), 
     'index' => 'bp', 
     'width' => '60px', 
     'filter_index' => 'billing.postcode' 
    )); 

,在一個爲我工作最近的項目。

+0

非常感謝這對我完美的工作。 – user1997432