Adding custom columns in order grid (Magento 1.7.0.0)

Adding custom columns in order grid (Magento 1.7.0.0)

August 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Adding custom columns in order grid (Magento 1.7.0.0)

Solving Custom Column Issues in Magento Order Grid

Introduction

In Magento development, customizing the order grid is a common requirement to display additional information about orders. However, during this process, you might encounter issues like incorrect column selection or pagination failures. This post aims to help you troubleshoot these problems and ensure your custom columns work correctly.

Understanding the Original Guide

The original guide you followed from Atwix provides a solid foundation for adding custom columns. It involves creating a local version of /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php and modifying key functions like _prepareCollection() and _prepareColumns().

The Issue with the Original Approach

The primary issue lies in joining the magento_sales_flat_order_address table to retrieve additional fields. While this works for displaying the columns, it causes a duplicate item error due to the group by clause missing from the SQL query.

The Suggested Fix: Adding GROUP BY Clause

To resolve the duplicate item issue, you need to add the GROUP BY clause to your SQL query in the _prepareCollection() function. This ensures that each row represents a unique order ID:

$collection->getSelect()->join(
    'magento_sales_flat_order_address',
    'main_table.entity_id = magento_sales_flat_order_address.parent_id',
    array('telephone', 'email')
)->group('main_table.entity_id');

The Unexpected Pagination Issue

After adding the GROUP BY clause, you encounter a pagination issue where only the most recent 20 records are displayed without any pagination links. This occurs because the prepareCollection() function is not returning the parent collection.

To fix this, ensure that you return the parent collection after your modifications:

return parent::_prepareCollection();

The Cause of the Pagination Failure

The pagination failure happens when the join query is executed without a LIMIT clause. Modern MySQL versions automatically add a limit of 1024 rows for queries with GROUP BY, resulting in only 20 records being displayed.

To resolve this, you need to explicitly set the limit in your SQL query:

$collection->getSelect()->join(
    'magento_sales_flat_order_address',
    'main_table.entity_id = magento_sales_flat_order_address.parent_id',
    array('telephone', 'email')
)->group('main_table.entity_id')->limit(1024);

Conclusion

Adding custom columns to the Magento order grid requires a careful approach to avoid duplicate item errors and pagination failures. By following this guide, you can ensure your custom columns display correctly with proper pagination.

Remember that modifying core files is generally discouraged in Magento development due to upgrade issues. Consider creating an extension or using a third-party module for a more stable solution.

For further reference on Magento development best practices, check out our Magento Development Guide at LaravelCompany.

What’s Next?

Now that you have resolved the custom column and pagination issues, explore other advanced techniques in our Magento Development Tutorials to enhance your e-commerce platform.

Magento 1 Database Admin Email

Our network