0

I am trying to customize the catalog and sales/order grids in magento.

There are 3 ways I know, by which I can implement by custom logic on these grids:

  • Multilevel inheritance

for example

class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    ...
    ...
}

and I use

class Royal_Marketplace_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid{
    ....
    // override only the methods I want to customize
}
  • Single inheritance by many classes

for example

class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    ...
    ...
}

and I use

class Royal_Marketplace_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    ....
    // reproduce all the functions
}
  • Events n Observers

If I don't use events and observers for some reason, I have 2 questions:

  1. Is my understanding correct?
  2. Which one is better among the first two methods? (I think 1st method is preferable, but many say 2nd is better).
1
  • I also prefer first method, as we inherit existing functionality. – Bijal Bhavsar Nov 6 '13 at 7:13
1

I always try to use observers to alter the core functionality but this is not always possible. When it's not possible I use the first method you described, extending the original class because:

  1. This is the recommended way of doing it
  2. On an upgrade the chances of something crashing are smaller.
  3. On an upgrade the chances of losing new features on the original class are smaller. Let's say that the new version a new method is added in the original class. If you choose the second approach then you won't have this method in your new class and this may lead to ... see point 2.
1
  • In my experience I find the class-override the quick'n dirty method. Whenever possible use an observer. Using observers usually requires a bit more creativity (there doesn't seem to be an obvious observer in each case), but the real advantage is that you avoid problems in the long run, still have compatibility with other modules etc. If you use class overrides, especially with the important classes like the product grid, order grid, checkout controller, sales model etc. you ARE going to run into problems. – Paul Hachmang Nov 6 '13 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.