1

I've added the a few columns to the sales_flat_order_gridtable. The values are obtained in these two events sales_order_resource_init_virtual_grid_columns (using addVirtualGridColumn() ) and sales_order_resource_update_grid_records (updating the table values for some more complex joins).

<add_order_grid_column_handle>
    <reference name="sales_order.grid">
        <action method="addColumnAfter">
            <columnId>product_names</columnId>
            <arguments>
                <header>Product(s) Name(s)</header>
                <index>product_names</index>
                <type>text</type>
            </arguments>
            <after>created_at</after>
        </action>
        [...]
    </reference>
</add_order_grid_column_handle>

<adminhtml_sales_order_grid>
    <update handle="add_order_grid_column_handle" />
</adminhtml_sales_order_grid>
<adminhtml_sales_order_index>
    <update handle="add_order_grid_column_handle" />
</adminhtml_sales_order_index>

However, when exporting a csv of the grid, it doesn't include the custom columns.

I found that the file is loaded using the grid block like this:

$this->getLayout()->createBlock('adminhtml/sales_order_grid');

But that, for some reason, is not loading the layout update I have written above, so the new columns are not used...

Is there any settings, or layout handle to add to this columns, so they are also used in the exported csv?

1
  • Is it your error solved?
    – Gem
    Commented Apr 27, 2017 at 6:41

1 Answer 1

2

The grid export is a different controller action, so the layout handle would be different, something like adminhtml_sales_order_exportCsv (didn't check if this is the exact handle). However, exportCsvAction doesn't seem to call loadLayout so probably using layout updates here wouldn't work.

From what I could tell by briefly looking at the code, there are three options, none of them extremely clean:

  1. Create a custom grid extending Mage_Adminhtml_Block_Sales_Order_Grid and add your logic to the _prepareColumns and _prepareCollection methods, then replace the core grid with the custom one
  2. Overwrite the Mage_Adminhtml_Block_Sales_Order_Grid block and add your logic in _prepareColumns and _prepareCollection.
  3. Overwrite the Mage_Adminhtml_Sales_OrderController controller, exportCsvAction and call addColumn on the $grid block object to add your columns
2
  • Thanks. I went with option 3. Calling the same methods as in the layout, but in plain old php. Like so: $grid->addColumnAfter( 'product_names', array( 'header' => "Product(s) Name(s)", 'index' => "product_names", 'type' => 'text', ), 'created_at' ); Commented Sep 18, 2015 at 21:12
  • @ Adi : I am using this method magento.stackexchange.com/a/171754/51361 for adding custom field on sales order grid. but when i export, the custom added column values not exported, how can i solve this error.
    – user51361
    Commented Apr 27, 2017 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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