Magento 1.x – OVERRIDE MAGENTO CONTROLLER


Sometimes we may need to override a method or add functionality in a controller of Magento.

We are going to assume that you already have a local extension.

In this case, we are going to override the saveAction() method of the Mage_Adminhtml_Sales_Order_InvoiceController located into app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php.

To do so, let’s perform the following steps:

  • app/code/local/Offset101/OverrideController/etc/config.xml

     

    <admin>  Is where we are going to override the route (it could be frontend or global instead).
    <routers> Is what we are going to add in our local extension.
    <adminhtml> Is whichever extension we want to override, in this case is Adminhtml and the vendor is Mage.
    offset101_overridecontroller  Is the identifier of our local extension.
    before=”Mage_Adminhtml” Is the overriden controller.
    Offset101_OverrideController_Adminhtml is Vendor_Modulename_Adminhtml just because we are overriding an adminhtml controller( it should be Offset101_OverrideController in case we want to override a frontend controller).

  • app/code/local/Offset101/OverrideExtension/controllers/Adminhtml/Sales/Order/InvoiceController.php

    Then remember to clean cache, and make a try!

In case that we need to override a frontend controller, we will need to proceed as follows (ie: to override the customer account create controller):

  • app/code/local/Offset101/OverrideController/etc/config.xml
  • app/code/local/Offset101/OverrideExtension/controllers/AccountController.php

    Then remember to clean cache, and make a try!