php - Using column aliases in Sales Order Grid field -


i'm trying add 2 fields (shipping postcode , billing postcod) magento 1.7ce's backend sales grid.

i'm doing overriding mage_adminhtml_block_sales_order_grid::setcollection(...) join table 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 , 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 , address_billing.address_type = "billing"',         array('postcode')     ); } 

and mage_adminhtml_block_sales_order_grid::_preparecolumns(...) add columns sales grid.

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

the issue both times need select postcode field sales/order_address table results in sql error

sqlstate[23000]: integrity constraint violation: 1052 column 'postcode' in order clause ambiguous 

i have tried use mysql's as alias differentiate between 2 postcodes, modifying setcollection(...) pass array('shipping_postcode'=>'postcode') , array('billing_postcode'=>'postcode') changing _preparecolumns(...) 'index' => 'shipping_postcode' , 'index' => 'billing_postcode'. resulted in sql error

sqlstate[42s22]: column not found: 1054 unknown column 'shipping_postcode' in 'where clause' 

how can achieve having both columns in sales grid?

let try first code

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 , address_shipping.address_type = "shipping"',         array('address_shipping.postcode shippingpostcode')     );      $collection->getselect()->join(         array('address_billing' => $collection->gettable("sales/order_address")),         'main_table.entity_id = address_billing.parent_id , address_billing.address_type = "billing"',         array('address_billing.postcode billingpostcode')     ); } 

second _preparecolumns() here,

protected function _preparecolumns(){      $this->addcolumn('shippingpostcode', array(         'header' => mage::helper('sales')->__('shipping postcode'),         'index' => 'shippingpostcode',         'filter_index' => 'address_shipping.postcode'      ));      $this->addcolumn('billingpostcode', array(         'header' => mage::helper('sales')->__('billing postcode'),         'index' => 'billingpostcode',         'filter_index' => 'address_billing.postcode'       ));  return parent::_preparecolumns();  } 

if want know more 'filter_index', comment in/out in this, try sorting in grid post code column. see different result. if remove filter_index, error in sorting.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -