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.