Magento - 在Magento 1.6.2的订单网格中添加邮政编码/邮政编码

时间:2013-01-21 15:08:16

标签: magento select collections grid

我正在尝试让订单网格显示客户的邮政编码/邮政编码。

我正在尝试将sales_flat_order_address别名加入到集合中,但没有成功。

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();
}

任何人都可以帮我找到解决方案。

1 个答案:

答案 0 :(得分:3)

返回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'
    ));

在最近的一个项目中,这对我有用。