1

my requirement is to add shipping cost in sales order grid,i added below code in _preparecolumns(),

$this->addColumn('base_shipping_amount', array(
    'header' => $helper->__('Shipping Amount (Base)'),
    'index'  => 'base_shipping_amount'
));

and added below code in _prepareCollection()

$collection->getSelect()->join(array('p' => 'sales/order_payment'), 'main_table.entity_id = p.parent_id', array(
    'payment_method' => 'method'
))

its giving me error . Any help would be appreciated.

  • magento 1 or 2? – Sukumar Gorai Jun 12 '18 at 15:08
  • magento 1.9.3.8 – vindhya Jun 12 '18 at 15:10
  • base_shipping_amount is not present on sales_flat_order_grid table. You need to join sales_flat_order to your collection. Do you want a working code? – Sukumar Gorai Jun 12 '18 at 15:46
  • how to do that ? could you please explain me in detail ? – vindhya Jun 12 '18 at 15:48
  • Yes please , it would be helpful if you provide me working code – vindhya Jun 12 '18 at 15:54
1

Copy

app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

to local directory

app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

And change the function _prepareCollection like below:

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('base_shipping_amount'=>'base_shipping_amount'));        
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

And the below block the position you want under _prepareColumns

$this->addColumn('base_shipping_amount', array(
    'header'=> Mage::helper('sales')->__('Shipping Cost'),
    'width' => '80px',
    'type'  => 'currency',
    'index' => 'base_shipping_amount',
    'currency' => 'base_currency_code',
));

This is for show shipping cost. You can join payment method with the same collection by following same steps.

Hope this help!

  • thanks sukumar for your time , but it didn't worked . its giving below error SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'shipping_method' in where clause is ambiguous, – vindhya Jun 12 '18 at 16:11
  • I have updated my answer. Please check. – Sukumar Gorai Jun 12 '18 at 16:12
  • its not working sukumar :( – vindhya Jun 12 '18 at 16:20
  • whats the error you are getting? Did you join some more tables? – Sukumar Gorai Jun 12 '18 at 16:21
  • your code added the shipping cost column but its not getting data to the rows – vindhya Jun 12 '18 at 16:30
0

Change below function code

protected function _prepareCollection()
    {
         $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('base_shipping_amount'=>'base_shipping_amount'));        
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

will show shipping price enter image description here

  • sorry prashant , shipping price column not added with your changes , instead "bill to name ","ship to name" columns became empty. – vindhya Jun 12 '18 at 16:03
  • Check updated code – Prashant Valanda Jun 12 '18 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.