Magento controller class override is something different then others classes. Controller override is not same as model, helper, block override. From my experience, Controller override is somehow hard and you need to get extra precise with the rewrite regular expression cause this causes a very hard time. Here is explained some controller override system.
Customer Account and Address Controller override:
At first create new module and files
1. /app/etc/modules/M4U_Customer.xml
2. /app/code/local/M4U/Customer/etc/config.xml
3. /app/code/local/M4U/Customer/controllers/AccountController.php
4. /app/code/local/M4U/Customer/controllers/AddressController.php
<?xml version="1.0"?>
<config>
<modules>
<M4U_Customer>
<active>true</active>
<codePool>local</codePool>
</M4U_Customer>
</modules>
</config>
Now configure in app/code/local/M4U/Customer/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<M4U_Customer>
<version>0.1.0</version>
</M4U_Customer>
</modules>
<frontend>
<routers>
<m4u_customer>
<use>standard</use>
<args>
<module>M4U_Customer</module>
<frontName>customer</frontName>
</args>
</m4u_customer>
</routers>
</frontend>
<global>
<rewrite>
<m4u_customer_account>
<from><![CDATA[#^/account/#]]></from>
<to>/customer/account/</to>
</m4u_customer_account>
<m4u_customer_address>
<from><![CDATA[#^/address/#]]></from>
<to>/customer/address/</to>
</m4u_customer_address>
</rewrite>
</global>
</config>
Now write your new controller class M4U_Customer_AccountController and define all override methods
# Controllers are not autoloaded so you will have to do it manually:
require_once 'Mage/Customer/controllers/AccountController.php';
class M4U_Customer_AccountController extends Mage_Customer_AccountController
{
// override existing method
public function loginPostAction()
{
// Define new login function. From now magento call this login method instead of existing method
}
// You can create new method as you needed.
public function newMethod()
{
// function logic
}
}
And also write your new controller class M4U_Customer_AddressController and define all override methods
require_once 'Mage/Customer/controllers/AddressController.php';
class M4U_Customer_AddressController extends Mage_Customer_AddressController
{
// override existing method
public function formPostAction()
{
// Define new post function. From now magento call this method instead of existing method
}
// You can create new method as you needed.
public function newMethod()
{
// function logic
}
}
You need to get extra precise with the rewrite regular expression cause this causes a very hard time. In this part.
<from><![CDATA[#^/account/#]]></from>
<from><![CDATA[#^/address/#]]></from>
Lets enjoy your new controller and write all necessary functions whose you wish to override.
THANK YOU.
Most Welcome ! For any kind of help just post your question. I will try to provide solution. Dont frustrated. Be cool
thanks for useful blog
Thanks for the post
Regards
Abdul Jamal
http://www.facebook.com/MoGaMboOo
Good Information
Hi I’m trying to override Mage_Catalog_CategoryController.php
I follow the rules base on your post but still unlucky.. I can’t override it.
Is there a other way to override that controller?
Tnx.
Awesome Post, Thank you very much.
But do you know how do we override a “Base adminhtml controller” in magento
hi Moinul Islam,
first of all thank u for ur awesome post.
but it is not working in magento1.6.help to resolve
thanks in advance
Yow, I think the config.xml not updated already. There was a best solution on this already.
I found a good one post.
http://www.spinonesolutions.com/2010/03/magento-controller-override/
I found my solution here in overriding Product controller. May it work on you too coz I only use 1.5
Pingback: How to overload controller in Magento? - XCoding.Info