How to add customer email to order grid in magento 1.4

How to add customer email to order grid in magento 1.4

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add customer email to order grid in magento 1.4

Extending the Order Grid in Magento 1.4: Adding Customer Email

In Magento 1.4, adding custom columns to grid views requires modifying the core files, which is generally discouraged due to upgrade issues. However, for this specific task of adding a customer email column to the order grid, we can follow a safer approach using an installer script.

Here’s a step-by-step guide on how to achieve this:

Step 1: Create the Installer Script

Create a new file named install-2.0.17.php in your Magento root directory. This number should match or be greater than the current version of your Magento instance.

// File: install-2.0.17.php
<?php
$installer = $this;
$installer->startSetup();

Step 2: Add the New Column to the EAV Structure

We’ll add a new field customer_email to the sales_flat_order table using the EAV structure.

$installer->run("
CREATE TABLE sales_flat_order_grid (
    entity_id int(10) unsigned NOT NULL auto_increment,
    created_at datetime NOT NULL default '0000-00-00 00:00:00',
    updated_at datetime NOT NULL default '0000-00-00 00:00:00',
    customer_id int(10) unsigned NOT NULL,
    increment_id varchar(50) NOT NULL default '',
    state varchar(32) NOT NULL default 'new',
    status varchar(32) NOT NULL default 'pending',
    is_closed tinyint(1) NOT NULL default '0',
    total_item_count int(11) NOT NULL default '0',
    quote_address_id int(10) unsigned NOT NULL,
    customer_email varchar(255),
    PRIMARY KEY (entity_id)
);
");

Step 3: Insert Data into the New Column

Next, we’ll need to populate this new customer_email column with data from existing orders.

$installer->run("
INSERT INTO sales_flat_order_grid (entity_id, customer_email)
SELECT entity_id, created_increment_id FROM sales_flat_order WHERE customer_email IS NOT NULL;
");

Step 4: Update the Grid Collection

Now we need to modify the Mage_Sales_Model_Mysql4_Order_Collection class to include our new column in the grid collection.

// File: app/code/core/Mage/Sales/Model/Mysql4/Order/Collection.php
public function _renderFiltersBefore() {
    // ...
    $this->addExpressionFieldToSelect('customer_email', '{{table}}.increment_id AS customer_email', array(
        'table' => Mage::getSingleton('core/resource')->getTableName('sales_flat_order_grid'),
        'field' => 'customer_email'
    ));
}

Step 5: Run the Installer Script

Finally, run this script from your Magento root directory using PHP:

php install-2.0.17.php

This will create and populate the sales_flat_order_grid table with customer email data.

Conclusion

While modifying core files is generally discouraged due to upgrade issues, in this specific case of extending the order grid in Magento 1.4, using an installer script provides a relatively safe approach.

The key takeaway here is that when working with legacy systems like Magento 1.4, it’s crucial to understand the system’s architecture and data flow before making changes. Always backup your data before running any scripts on live environments.

For more advanced customizations in modern eCommerce platforms, consider migrating to a platform like Laravel Commerce (https://laravelcompany.com/laravel-commerce) which provides a clean slate for building high-performance eCommerce applications with the power of Laravel.

Remember, while Magento 1.4 is an outdated version, understanding its core mechanics can provide valuable insights into how eCommerce platforms handle data and customizations. Always strive to keep your knowledge up-to-date as technology evolves rapidly in this industry.

Happy coding!

Magento 1 Database Admin Deployment

Our network