user1851806
user1851806

Reputation: 29

Magento (v 1.7.0.2) - Add "Shipping Method" column in Sales Order Grid

I'm trying to add a new column for Shipping Method (Standard, Priority, Express) in the Sales Order Grid located here:

/home/html/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

I've researched tons of methods but either it's for an older version of magento, or simply doesn't work. From what I understand, I need to do the following:

  1. Edit _prepareCollection()
  2. Add a case in _prepareColumns() like the following:

$this->addColumn('shipping_description', array( 'header' => Mage::helper('sales')->__('Shipping Method'), 'index' => 'shipping_description', ));

Can someone please help me get this figured out?

Upvotes: 2

Views: 5059

Answers (3)

Anant
Anant

Reputation: 3077

For adding shipping info into sales order grid You have to override Mage_Adminhtml_Block_Sales_Order_Grid class. For this create your own module. => In config.xml in block section
paste below xml code

<globals>
    <block>
        <adminhtml>
            <rewrite>
                <sales_order_grid>Yourpackage_Yourmodule_Block_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
    </block>
<globals>

Now define a class Yourpackage_Yourmodule_Block_Sales_Order_Grid and put it into package_name/module_name/Block/Sales/Order/Grid.php

class Yourpackage_Yourmodule_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareCollection()
{

    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->
    joinLeft('sales_flat_order', 'main_table.entity_id=sales_flat_order.entity_id', array("shipping_desc"=>"shipping_description"));

    $this->setCollection($collection);
    return $this;
}

protected function _prepareColumns()
{
    $this->addColumnAfter('shipping_desc', array(
        'header'=> Mage::helper('sales')->__('Shipping Descr #'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'shipping_desc',
    ),"real_order_id");
    return parent::_prepareColumns();

}

}

Upvotes: 2

VEO
VEO

Reputation: 61

This extension should give you a very quick, easy solution to your problem http://www.magentocommerce.com/magento-connect/OSdave/extension/5814/orders_grid_payment_shipping_filters

Upvotes: 0

Celldweller
Celldweller

Reputation: 309

I am still looking for a good solution myself. But as an approach I would like to contribute my knowledge so far based on Magento 1.7

  • I prefer use of setCollection instead of _prepareCollection(). It seems there are less problems with filtering etc. when using setCollection
  • The perfect attribute is so close yet so far. shipping_description can be found in sales_order_flat. Unfortunately the default collection is based upon sales_flat_order_grid. One possible solution is to switch this by overwriting _getCollectionClass

    protected function _getCollectionClass()
    {
        //return 'sales/order_grid_collection';
        return 'sales/order_collection';
    }
    

    It's important to say that this leads to other problems. E.g. shipping name and billing name are empty because they got their info from sales_flat_order_grid. We could get them from sales_flat_order_address but I am not sure if this leads to far away from a good solution...

  • Another approach is to join with sales_order_flat. This way we keep all information from sales_flat_order_grid and also can get the shipping_method. Problem here is a count(*) statement that occurs while filtering. The error is about an ambigious increment_id. At the moment I think it is a Magento bug because increment_id should not be used without conjunction to its table.

  • Not to forget a third way: We could extend saled_flat_order_grid and add shipping_method, but I think that would be way to harsh. Dont't touch app/code/core und the tables as long as nobody stands behind you with a gun in his hands ;-)

So far I am still undecided which way to go. Perhaps there is another (better) way that I didn't list here?

Upvotes: 0

Related Questions