Jigar.Oza
Jigar.Oza

Reputation: 51

How to add custom field in to order grid for magento admin panel

I have query for order grid in magento admin panel. I have to display purchase products with there qty, also total weight for particular order, weight unit. Can any one help me how can i achieve this task.

I tried many solution but not getting it.

Upvotes: 0

Views: 1157

Answers (2)

miszyman
miszyman

Reputation: 121

You want to do it on the standard grid BE Menu>Sales>Orders (app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php)? -If yes then look at this article, it describes a simple modification of the grid. You will need to modify the _prepereCollection() and _prepareColumns() methods in order to display data.

Firstly try to write raw SQL which will do what you want (grouping by order). Remember to take into consideration the correct column for qty - as the total order QTY can be different than actually shipped QTY

Upvotes: 0

You can use renderer for add custom field your code in config.xml

<core_block_abstract_prepare_layout_before> 
    <observers>
      <core_block_abstract_prepare_layout_before_handler> 
        <type>model</type> 
        <class>adminordergridcustom/observer</class> 
        <method>adminordergridcolumn</method>
        <args></args>
      </core_block_abstract_prepare_layout_before_handler>
    </observers>
  </core_block_abstract_prepare_layout_before>

Your code in observer.php file

       public function adminordergridcolumn(Varien_Event_Observer $observer)
        {
            $block = $observer->getEvent()->getBlock();

            if($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)
            {

            $block->addColumnAfter('qty', array(
                'header' => Mage::helper('sales')->__('Qty'),
                'index' => 'qty',
            ),'imported');

            }
        }


You need to add column 'qty' in database 'sales_flat_order' table 

and also update this field on this event . You will get value in grid.

Upvotes: 1

Related Questions