How to properly add a shipping_description column in magento order grid?

后端 未结 3 1089
不思量自难忘°
不思量自难忘° 2021-01-24 21:51

There are many tutorials and suggestions including installing a custom extensions etc.

I\'ve added the shipping_description fine based on various tips and tricks by modi

3条回答
  •  太阳男子
    2021-01-24 22:28

    The following worked in my case. Sorting now works from every single field. No core files overridden.

    Step by step for someone who is in the same boat. Tested in 1.8.1

    1. Copy your Grid.php from

      /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php to /app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

      if the path doesn't exist create it.

    2. Open your new Grid.php and add the following code into _prepareCollection() after getResourceModel line:

      $collection->getSelect()->join(array('mt'=>'sales_flat_order'), 'mt.entity_id = main_table.entity_id', array('mt.increment_id','mt.store_id','mt.created_at','mt.shipping_description','mt.status','mt.base_grand_total','mt.grand_total'));

      $collection->getSelect()->group('main_table.entity_id');

    3. Add the following code into _prepareColumns() function (in between your desired addColumn() calls)

      $this->addColumn('shipping_description', array( 'header' => Mage::helper('sales')->__('Delivery'), 'type' => 'text', 'index' => 'shipping_description',
      'filter_index' => 'mt.shipping_description', ));

    4. Find addColumns() functions for increment_id, store_id, created_at, base_grand_total, grand_total, status and add the following argument in each:

      'filter_index' => 'mt.___your_column_name____',

    Any suggestion on how to optimise above code are welcome.

提交回复
热议问题