1

How to add tracking number column to order grid?

I tried with this code but doesn't work

$this->addColumn('tracking', array(
            'header' => Mage::helper('sales')->__('tracking'),
            'index' => 'tracking',
            'type'  => 'number',
            'width' => '70px',
            'options' => Mage::getModel('sales/order_shipment')->getTrackingNumbers(),
        ));

Any ideas please..

Update:

By the way i edit on sales grid.php to add this code

$collection->getSelect()
        ->from(
            array(),
            array(
                'track_number' => new Zend_Db_Expr('(
                    SELECT GROUP_CONCAT(`t`.`track_number` SEPARATOR ",")
                    FROM `bg8_sales_flat_shipment_track` as `t`
                    WHERE `main_table`.`entity_id` = `t`.`order_id`
                )'),
            )
        );

Its working fine but the filter not working i tried to add public & protected function and its freezing when i add value to search on it.

1

If you want to add tracking no at sales grid then you need to add sales_flat_shipment_track table with sales grid order collection table.

Order may have multiple tracking no. ,So you need to follow Atwix blog in order to implement your requirement.

add below to observer class

$select->joinLeft('sales_flat_shipment_track', 'sales_flat_shipment_track.order_id = main_table.entity_id', 
        array('trackingno' => new Zend_Db_Expr('group_concat(sales_flat_shipment_track.track_numberSEPARATOR ", ")')));
$select->group(‘main_table.entity_id');

Just add the following code to our layout extendedgrid.xml:

<action method="addColumnAfter">
    <columnId>trackingno</columnId>
    <arguments>
        <header>Tracking no</header>
        <index>trackingno</index>
        <type>text</type>
    </arguments>
</action>

Now.change

<action method="addColumnAfter">
    <columnId>trackingno</columnId>
    <arguments helper="atwix_extendedgrid/getTrackingnoColumnParams"/>

</action>

at helper class:

public function getTrackingnoColumnParams()
{
    return array(
        'header' => 'Tracking no',
        'index' => 'trackingno',
        'type' => 'text',
        'filter_condition_callback' => array('Atwix_ExtendedGrid_Model_Observer', 'filtertrackingno'),
    );
}

then at filtertrackingno

public function filtertrackingno($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $collection->getSelect()->having(
        "group_concat(sales_flat_shipment_track.track_number SEPARATOR ', ') like ?", "%$value%");

    return $this;
}
  • Thank you @amit-bera for sharing this with me. Can you please which files should i edit. I am sorry i'm new with Magento. I updated the post please check out it. – MagEGY May 4 '16 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.