我正在尝试将两个字段(Shipping Postcode和Billing Postcod)添加到Magento 1.7CE的后端销售网格中.
我是通过重写Mage_Adminhtml_Block_Sales_Order_Grid::setCollection(...)来加入表格来做到这一点的sales/order_address.
public function setCollection($collection){
parent::setCollection($collection);
$collection->getSelect()->join(
array('address_shipping' => $collection->getTable("sales/order_address")),
'main_table.entity_id = address_shipping.parent_id AND address_shipping.address_type = "shipping"',
array('postcode')
);
$collection->getSelect()->join(
array('address_billing' => $collection->getTable("sales/order_address")),
'main_table.entity_id = address_billing.parent_id AND address_billing.address_type = "billing"',
array('postcode')
);
}
Run Code Online (Sandbox Code Playgroud)
而Mage_Adminhtml_Block_Sales_Order_Grid::_prepareColumns(...)将这些列添加到销售网.
protected function _prepareColumns(){
$this->addColumn('shipping_postcode', array(
'header' => Mage::helper('sales')->__('Shipping Postcode'),
'index' => 'postcode',
));
$this->addColumn('billing_postcode', array(
'header' => Mage::helper('sales')->__('Billing Postcode'),
'index' => 'postcode',
));
return parent::_prepareColumns();
}
Run Code Online (Sandbox Code Playgroud)
问题是,我需要postcode从sales/order_address表中选择字段,这会导致SQL错误
SQLSTATE[23000]: Integrity …Run Code Online (Sandbox Code Playgroud)