2

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

我正在尝试将 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();
}

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

4

1 回答 1

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

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

于 2013-01-21T15:36:39.353 回答