Question

I want to call addExportType() to add my custom export type to sales order grid. I can do it two ways:

  1. Either rewrite the admin sales order grid :Mage_Adminhtml_Block_Sales_Order_Grid and add the method call from there OR

  2. Hook into the event - adminhtml_block_html_before and in my observer method check if the block instance I am getting is for the order grid and call addExportType() on it if it is indeed an instance of the class I am interested in.

The advantage of point 2 is that it makes the extension less vulnerable to conflicts with other over-writes of the sales order admin grid but the disadvantage is that it will be called for every admin template child block for which this event is triggered.

What would you choose and why?

Was it helpful?

Solution

It seams you already have listed down the advantages each approach has over the other.
There is no right answer for this one.
Just choose wisely.

I can tell you what I would do and why.
If you need this for a project then just rewrite the class. It's faster. and in case you install some extension related to the orders grid just make sure it does not conflict with your extension. If it does, the fix should be easy.

If you are doing it for a commercial extension, the use the observer approach. And state it in the readme file.
As a third party extension, you want to override as less as possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top