Add and show new column in sales_flat_order and show this at order grid in magento

Add and show new column in sales_flat_order and show this at order grid in magento

August 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add and show new column in sales_flat_order and show this at order grid in magento

Adding a New Column to sales_flat_order Table in Magento

Hello developers! Today, we’re going to tackle a common challenge faced by many Magento enthusiasts - adding a new column to the sales_flat_order table and displaying it on the admin order grid.

The Goal

Our objective is to add a new column named ‘exported’ to the sales_flat_order table and make it visible in the admin order grid. This will allow us to track whether an order has been exported or not.

Step 1: Add the Column to the Database

The first step involves adding the new column to the database directly. For this, you need to add a left foreign key field named ‘exported’ to the sales_flat_order table. You can do this using SQL:

ALTER TABLE sales_flat_order ADD exported INT(1) NOT NULL DEFAULT 0;

The INT(1) data type ensures that we only have binary values (0 or 1), and NOT NULL DEFAULT 0 sets the default value to false.

Step 2: Modify the Collection

Next, we need to modify the collection used in the order grid to include our new column. Open the following file:

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

In the _prepareCollection() method, add a join for our new column:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->getCollectionClass())
        ->addAttributeToSelect('*')
        ->joinAttribute('exported', 'sales/order', 'sales_flat_order.entity_id', null, 'left');
}

This joins the sales_flat_order table with our new column.

Step 3: Add the Column to the Grid

Now let’s add our new column to the order grid. In the _prepareColumns() method, add the following code after other columns:

protected function _prepareColumns()
{
    // ... existing code ...

    $this->addColumn('exported', array(
        'header' => Mage::helper('sales')->__('Exported'),
        'index' => 'exported',
        'type'  => 'options',
        'name'  => 'exported',
        'options' => array(
            0 => 'No',
            1 => 'Yes'
        ),
    ));

    // ... existing code ...
}

This adds a new column named ‘exported’ with options for “Yes” and “No”. The index parameter is set to the name of our new column.

Step 4: Save Your Changes

After making these changes, save your file. The new column should now be visible in the admin order grid under the “Exported” header.

Remember that you’ll need to clear your cache after making changes to see them reflected immediately. You can do this from the main menu: System > Cache Management > Flush Magento Cache.

Conclusion

Adding a new column to the sales_flat_order table and displaying it on the admin order grid is a straightforward process once you understand how the data is retrieved and displayed in Magento.

For more advanced customizations like adding new attributes to products or customers, I highly recommend checking out our guide on extending Magento models.

This should resolve your issue. If you’re still facing problems or have any other questions about Magento development, feel free to ask!

Database Admin Orders Import/Export

Our network