Magento show and edit tracking number field in order overview

Magento show and edit tracking number field in order overview

September 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento show and edit tracking number field in order overview

Showing and Editing Tracking Number Field in Magento Order Overview

Hello developers,

Today, I will guide you through the process of showing and making the tracking number field editable in the order overview section of your Magento storefront. This is a common requirement for many merchants who want to manage their shipping processes more efficiently.

Step 1: Enabling the Tracking Field in Grid.php

To start, we need to extend the existing grid file and add a new column for the tracking number field. Here’s a general outline of how you can do this:

Extending Grid.php

Navigate to your custom module directory (e.g., app/code/local/Company/Shipping/etc/config.xml).

Open the XML configuration file and locate the <core_block_abstract_prepare_layout_before> section.

Add an observer for the SNH_ShipMailInvoice_Observer_addTrackingColumnToGrid event:

<core_block_abstract_prepare_layout_before>
    <observers>
        <SNH_ShipMailInvoice_Observer_addTrackingColumnToGrid>
            <type>model</type>
            <class>SNH_ShipMailInvoice_Model_Observer</class>
            <method>addTrackingColumnToGrid</method>
        </SNH_ShipMailInvoice_Observer_addTrackingColumnToGrid>
    </observers>
</core_block_abstract_prepare_layout_before>

This tells Magento to call the addTrackingColumnToGrid method in your observer class whenever the grid layout is prepared.

Adding a Column (Hide an Existing Column)

Next, create or update your Observer.php file located at app/code/local/Company/Shipping/Model/Observer.php:

public function addTrackingColumnToGrid($observer)
{
    $block = $observer->getEvent()->getBlock();
    if ($block instanceof Mage_Adminhtml_Block_Sales_Order_grid) {
        // Add new tracking column
        $block->addColumn('tracking_number', array(
            'header' => Mage::helper('sales')->__('Tracking number'),
            'index' => 'tracking_number',
            'type' => 'input',
            'width' => '120px',
            'renderer' => 'SNH_ShipMailInvoice_Block_Adminhtml_Renderer_addTrackingColumnToGrid'
        ));

        // Hide the existing column (optional)
        $block->removeColumn('increment_id');
    }
}

In this example, we add a new tracking number column and also remove the default increment_id column for demonstration purposes. You can customize the widths and header labels as needed.

Step 2: Populating the Grid with Tracking Information

To populate the grid with available tracking info, you’ll need to create the corresponding renderer class and lookup the tracking numbers per order.

Creating the Renderer Class

Create a new PHP file at app/code/local/Company/Shipping/Block/Adminhtml/Renderer/addTrackingColumnToGrid.php:

class SNH_ShipMailInvoice_Block_Adminhtml_Renderer_addTrackingColumnToGrid extends Mage_Adminhtml_Block_Text
{
    public function render(Varien_Object $row)
    {
        // Populate the tracking number field with available information
        // You can customize this logic to match your specific requirements

        return parent::render($row);
    }
}

Currently, the renderer class is empty because we need to figure out how to populate the tracking information.

Looking Up Tracking Numbers per Order

Update your Observer.php file from Step 1:

public function addTrackingColumnToGrid($observer)
{
    // ... (previous code)

    $block = $observer->getEvent()->getBlock();
    if ($block instanceof Mage_Adminhtml_Block_Sales_Order_grid) {
        // Add new tracking column
        $block->addColumn('tracking_number', array(
            'header' => Mage::helper('sales')->__('Tracking number'),
            'index' => 'tracking_number',
            'type' => 'input',
            'width' => '120px',
            'renderer' => 'SNH_ShipMailInvoice_Block_Adminhtml_Renderer_addTrackingColumnToGrid'
        ));

        // Hide the existing column (optional)
        $block->removeColumn('increment_id');

        // Lookup tracking numbers per order in the grid
        $orderCollection = Mage::getResourceModel('sales/order_collection');
        foreach ($orderCollection as $order) {
            // Populate the tracking number field for each order
            // You can customize this logic to match your specific requirements

            // The following code is a placeholder; you'll need to adapt it based on your actual tracking data structure
            $tracknums = array(); 
            foreach ($order->getShipmentsCollection() as $shipment) {
                foreach ($shipment->getTracksCollection() as $track) {
                    $tracknums[] = $track->getData('tracking_number');
                }
            }

            // Set the tracking number for the current order row in the grid
            // You'll need to replace this logic with your actual implementation
            $order->setTrackingNumber(implode(', ', $tracknums));
        }
    }
}

In this updated code, we iterate through each order and lookup the associated shipments. We then extract the tracking numbers and set them as the tracking_number value for each order row in the grid.

Remember to replace the placeholder logic with your actual implementation based on your store’s specific tracking data structure.

Step 3: Processing Mass Action and Storing Tracking Information

This step involves handling the “Mass Action” dropdown option, processing selected items, and storing the tracking ID to the shipment. Since this is a more advanced topic, it would require additional code customization and integration with your existing shipping processes.

You can start by extending the mass action functionality in your controller or event observer classes and integrating it with your tracking information handling logic from Step 2.

Conclusion

In summary, showing and editing the tracking number field in the Magento order overview involves several steps:

  1. Configuring the event observer to add a new column to the grid.
  2. Creating a renderer class to populate the tracking number field with available information.
  3. Looking up tracking numbers per order using the appropriate collection objects.
  4. Customizing your logic based on your specific tracking data structure.

Remember that this is a general guide, and you may need to adapt it to fit your store’s unique requirements. If you have any questions or encounter issues during implementation, please don’t hesitate to reach out for further assistance.

Happy coding!

Learn more about Magento development best practices and extension customization at Laravel Company’s official website.

Database Extensions Themes Admin

Our network