Today I am going to show you how to add column to magento order grid through our custom module either anyway. I mean either by overriding the order grid block or by observing the event. In my previous article add product attribute as column to category products section I have displayed how you can add some extra column to product grid. Now I am just showing you how you can simply add postcode and company as a extra column to order grid in magento. What I know its just a simple , Like all other grid section you have to do two things one is add column to by _prepareColumns methods and other is set collection query then your work is done.So for adding extra column to the those two method you will either override or use observer. I always choose the second option that is event observer.Because it is most reliable one to do .So here I will let you know both methods how you can do easily setp by step.

add extra column to magento order grid
add extra column to magento order grid

First method:

Event Observer:

If you have little bit idea on event observer concept in magento then you can easily understand what I am explaining lets start with event observer way.

One best thing I would like tell you that how to identify which event is suitable for your requirement.This is the simple way I mean just go to mage.php though dir : app/mage.php and search for dispatchEvent function near to line No – 444 and do you log by Mage::log($name); or Mage::log($name,1,’name.log’,true) make sure log is enabled in magento configuration filed and see which event is suitable for your requirement.I am not explaining more on this topic because this is not our topic.Here our topic is different ,so lets come to our point.I have used here two event which is full-filling my requirement .You can do the same if like this concept.

lets come to the first file called config.xml file,which is located in our module by dir :
e.g: /app/code/local/JRB/Ordercolumns/etc/config.xml

In this above code I have defined two methods through different event called as beforeGridCollectionLoad by the event sales_order_grid_collection_load_before and other is addNewColumnToOrderGrid by the event core_block_abstract_prepare_layout_before.

lets see what are the logic I have implementted in that observer file. I would like to tell you that logic is that I have just add the column by taking method _prepareColumns as a block object and add the column by addColumn method and fr the collection I also just have get collection object and added some extra query to that collection to get my requirement.Lets see what is that

and other is

Second method:

Overriding Blocks:

Sometimes if you are not getting success on the above methods and you don’t have enough time to research then do this easiest methods and do your work as quick as possible. Lets see how we can do it by overriding blocks and implement on our custom module.

lets come to the first file called config.xml file same as above method,which is located in our module by dir :
e.g: /app/code/local/JRB/Ordercolumns/etc/config.xml

In the above code I mean in config.xml file I have overrides the order_grid method to my custom order_grid method through rewrite tag.Lets what the logic I have placed in block grid file.

Here in the block file I just have add the column trough _prepareColumns and set the collection through setCollection method nothing else. All are the same logic for grid section.

Hope you enjoyed the article add column to magento order grid and never hesitate to share to help others also you can get the full module from here JRB_Ordercolumns


add column to magento order grid
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 6 years and in the mean time he has developed enormous amount of modules and customisation of sites. He loves to write blogs and travel for long journeying.

Latest posts by Jyotiranjan Biswal (see all)

Tagged on:                                                 

Leave a Reply

Your email address will not be published. Required fields are marked *