Magento – How to Add Shipping and Tax to Sales Order Grid

order-gridsales

So I wanted to change the columns in the sales – order – grid

I created my own version of the Grid.php (located at app\code\local\Mage\Adminhtml\Block\Sales\Order\Grid.php)

in _prepareCollection() I added

$collection->getSelect()->join(
    'sales_flat_order',
    'main_table.entity_id = sales_flat_order.order_id',
    array(Shipping_column)
);

(not correct shipping column – this just an example)

and also added the column to _prepareColumns()

Logged in to Magento admin and I have a new column – no problem

Then I wanted to add the tax from sales_flat_order

Again I added in _prepareCollection() and _prepareColumns()

$collection->getSelect()->join(
    'sales_flat_order',
    'main_table.entity_id = sales_flat_order.order_id',
    array(tax_column)
);

Logged into Magento admin and page went crashing – never loaded and ended in temporary error (502) – both backend and frontend. Had to call support to restart.

What did I do wrong?

Best Answer

The field order_id does not exist in sales_flat_order. You need use entity_id instead of order_id and columns is working, it should be shipping_amount instead Shipping_column and tax_amount field to join query

so change to

join(
    'sales_flat_order', 
    'main_table.entity_id = sales_flat_order.entity_id ',
    array(shipping_amount,tax_amount)
);