Searching sales order grid redirects to dashboard in magento 1.7

Searching sales order grid redirects to dashboard in magento 1.7

October 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Searching sales order grid redirects to dashboard in magento 1.7

Solving the Sales Order Grid Search Issue in Magento 1.7

If you’re facing search issues with your custom sales order grid in Magento 1.7, this guide will help you resolve the ambiguity error and prevent redirection to the dashboard.

Understanding the Problem

When you add new columns to the Sales_Order_Grid using a custom module, Magento’s built-in search functionality may encounter conflicts due to the presence of multiple fields with similar names (like increment_id). This results in an integrity constraint violation error and redirects the user to the dashboard instead of filtering the grid.

Analyzing Your Current Code

Your current implementation in Excellence_Salesgrid_Block_Adminhtml_Sales_Order_Grid demonstrates a common approach but misses some crucial steps for handling complex joins.

The key issues are:

  • You’re adding multiple columns using addColumnAfter() without considering the join tables required to fetch their data.
  • You’re manually filtering each column separately, which can lead to ambiguity when Magento tries to combine these filters into a single SQL query.

Resolving the Ambiguity Error

To fix this, you need to ensure that all relevant tables are joined correctly before applying any filters. Here’s an updated version of your _addColumnFilterToCollection() method:

protected function _addColumnFilterToCollection($column)
{
    if ($this->getCollection()) {
        $this->getCollection()->join('sales_flat_order_address' => 'o', 'main_table.entity_id = o.parent_id');
        $this->getCollection()->joinLeft(
            array('sales_flat_order_item' => 'oi'),
            'main_table.entity_id = oi.order_id'
        );
    }

    // Rest of your existing code

    return parent::_addColumnFilterToCollection($column);
}

I’ve added two joins:

  1. sales_flat_order_address: This table contains shipping data like city, telephone, region, and postcode.
  2. sales_flat_order_item: This table is required to fetch product-related information.

By joining these tables before applying filters, you ensure that all necessary fields are available without causing ambiguity in the SQL query.

Updating the Column Preparation

In your _prepareColumns() method, I recommend adding columns using addColumnSetAfter() instead of addColumnAfter(). This allows you to group related columns together and maintain better control over their order. Here’s an updated version:

protected function _prepareColumns()
{
    $this->addColumnSetAfter('shipping_details', array(
        'label' => Mage::helper('sales')->__('Shipping Details'),
        'style' => 'width:200px;',
        'collapsable' => true,
        'columns' => array(
            // Add your shipping-related columns here, e.g.:
            // 'shipping_description',
            // 'method',
            // 'shipping_city',
            // 'shipping_telephone',
            // 'shipping_region',
            // 'shipping_postcode',
        ),
    ), 'increment_id');

    return parent::_prepareColumns();
}

Preventing Redirection to the Dashboard

To prevent redirection to the dashboard, you need to ensure that your custom grid is properly registered and accessible. Check if you have correctly defined your collection model in config.xml:

<models>
  <salesgrid>
    <class>Excellence_Salesgrid_Model</class>
    <resourceModel>salesgrid_resource</resourceModel>
  </salesgrid>
  <salesgrid_resource>
    <class>Excellence_Salesgrid_Model_Resource</class>
  </salesgrid_resource>
</models>

<resources>
  <salesgrid_setup>
    <setup>
      <module>Excellence_Salesgrid</module>
    </setup>
    <connection>
      <use>core_setup</use>
    </connection>
  </salesgrid_setup>
  <salesgrid_read>
    <table name="sales/order_grid"></table>
    <table name="sales/flat_order_address"></table>
    <table name="sales/flat_order_item"></table>
  </salesgrid_read>
</resources>

Ensure that the module is properly installed and enabled. If everything is set up correctly, you should be able to search orders without encountering redirection issues.

Conclusion

In this guide, we’ve identified and resolved the ambiguity error caused by adding new columns to the sales order grid in Magento 1.7. By joining required tables before applying filters and using proper column grouping, you can maintain a functional and efficient custom grid that allows for searching without redirection problems.

Remember to test your changes thoroughly and monitor performance, as complex joins can impact grid load times if not optimized properly.

For more advanced customization tips and best practices in Magento development, be sure to check out our Magento Custom Development Services at Laravel Company. Our team of experienced developers is ready to help you tackle any Magento-related challenges.

Magento 1 Database Extensions Admin

Our network