Magento - How to add country column in Orders grid filter? -
i tried:
$collection = mage::getresourcemodel($this->_getcollectionclass()); $collection->oinattribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left'); $this->setcollection($collection); return mage_adminhtml_block_widget_grid::_preparecollection();
but results blank. please me add country column in orders grid. thanks.
copy app/code/core/mage/adminhtml/block/sales/order/grid
app/code/local/mage/adminhtml/block/sales/order/grid
in file add below code append billing address order grid preparecollection
function
$collection->getselect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type = 'billing'");
full code
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('telephone','city','postcode','country_id' ) )->where("sales_flat_order_address.address_type = 'billing'"); $this->setcollection($collection); return parent::_preparecollection(); }
and add below code _preparecolumns()
$this->addcolumn('country_id', array( 'header' => mage::helper('sales')->__('country id'), 'index' => 'country_id', 'filter_index' => 'sales_flat_order_address.country_id', ));
if want country list add below code _preparecollection()
$this->addcolumn('country_id', array( 'header' => mage::helper('sales')->__('country id'), 'index' => 'country_id', 'type'=> 'options', 'options'=>$this->getallcountry(), 'filter_index' => 'sales_flat_order_address.country_id', ));
and add new function on file
public function getallcountry(){ $options = mage::getresourcemodel('directory/country_collection')->load()->tooptionarray(); $countries = array(); foreach($options $options){ $countries[$options['value']]=$options['label']; } return $countries; }
more details on http://bluehorse.in/blog/how-to-add-some-field-or-column--into-magento-order-grid-in-magento-or-customized-magento-order-grid.html
http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/
Comments
Post a Comment