Reputation: 23
I am trying to get the order grid to display the postcode/ zip code of the of the customer.
I am trying to join the sales_flat_order_address alias with the collection but to no success.
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();
}
Can any one please help me figure out a solution for this.
Upvotes: 2
Views: 1786
Reputation: 700
Before return parent::_prepareCollection(); You should create a join:
$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'));
If you want the shipping postcode instead, use:
$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'));
And in the method _prepareColumns paste:
$this->addColumn('bp', array(
'header' => Mage::helper('sales')->__('Billing Postcode'),
'index' => 'bp',
'width' => '60px',
'filter_index' => 'billing.postcode'
));
That worked for me in a recent project.
Upvotes: 3