Magento - How to add Ship to information to order grid in Magento 1.5.1.0

Magento - How to add Ship to information to order grid in Magento 1.5.1.0

July 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - How to add Ship to information to order grid in Magento 1.5.1.0

Title: How to Add Ship To Information to Order Grid in Magento 1.5.1.0

Introduction

As a Magento developer, you may want to display additional information on the sales order grid in the admin panel for better management and oversight of your orders. In this post, we’ll explore how to add ship-to information such as name, address, city, state, and zip code to the order grid in Magento 1.5.1.0.

Understanding the Magento Order Data Structure

Before proceeding, it’s crucial to understand that Magento stores order data across multiple tables in its database. The main table is sales_flat_order, which contains general order information like entity_id (order ID), customer_email, and shipping_description. However, the ship-to address details are stored in the sales_flat_order_address table.

Adding Customer Email to the Order Grid

Magento allows you to extend the sales order grid by joining additional tables using the collection object’s joinLeft method. In this approach, you can add columns from joined tables to the grid view.

Ben Incani provided a great example of adding customer email to the order grid in his StackExchange answer How to Add Customer Email to Order Grid in Magento 1.4?. Here’s the relevant code snippet:

$collection->getSelect()->joinLeft(array('sfo' => 'sales_flat_order'),
    'sfo.entity_id=main_table.entity_id',
    array('sfo.customer_email', 'sfo.shipping_description'));

This code joins the sales_flat_order table with the main order collection (main_table) based on the entity_ids, and it adds two new columns—customer email and shipping description—to the grid view.

Adding Ship-To Information to the Order Grid

Now let’s try to add ship-to information using a similar approach. We’ll join the sales_flat_order_address table with the main order collection:

$collection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),
    'sfoa.parent_id=main_table.entity_id',
    array('sfoa.postcode'));

In this code, we join the sales_flat_order_address table with the main order collection based on the parent_id (which corresponds to the order entity_id) and add a new column—postal code (zip)—to the grid view.

However, you might encounter an error similar to the one mentioned in the question:

Item (Mage_Sales_Model_Order) with the same id "10860" already exist

This error occurs because Magento doesn’t allow duplicate orders with the same entity_id. To resolve this issue, we need to update our join condition.

Updating the Join Condition

Let’s update the join condition to use the correct foreign key relationship between sales_flat_order and sales_flat_order_address:

$collection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),
    'sfoa.order_id=main_table.entity_id',
    array('sfoa.postcode'));

In this updated code, we join the tables based on the order_id (the foreign key in sales_flat_order_address) and the entity_id of the main order collection.

Displaying Other Ship-To Information

Now that you have successfully added the postal code to the grid view, let’s display other ship-to information such as name, address, city, and state. You can follow a similar approach by adding more columns to the join array:

$collection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),
    'sfoa.order_id=main_table.entity_id',
    array(
        'sfoa.postcode',
        'sfoa.name',
        'sfoa.street',
        'sfoa.city',
        'sfoa.region'
    ));

In this example, we added columns for the name, street address, city, and region (state) to display ship-to information in the order grid.

Conclusion

Adding ship-to information to the Magento sales order grid allows you to manage your orders more efficiently by having all relevant data at hand. By leveraging the collection object’s joinLeft method, you can easily extend the default grid view with additional columns from joined tables.

Remember that proper database relationships and understanding of the data structure are essential for successful implementation. Always test your code in a development environment before applying it to a live store.

For more advanced customizations and Magento best practices, visit Laravel Company and explore their extensive resources on Magento development.

Magento 1 Database Admin Email

Our network