The Problem:
You want to override a Controller’s action with a custom action.
Magento Enterprise v1.6.0.0
The Solution:
I ran into some issues trying to override a controller’s action yesterday. I think it mainly stems from a version change, but at any rate here’s the “new” way to do it. This comes from a helpful post on the Magento forums.
In this example my custom modules’s namespace is “Spinonesolutions” and I’m going to override the createPostAction in Mage_Customer_AccountController.
Start by creating a bare bones custom module; if you don’t know how to do this check out Magento – Part I : Custom Module.
I’ve only got two files in my custom module; controllers/AccountController.php and etc/config.xml.
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Spinonesolutions_Customer>
<version>0.0.1</version>
</Spinonesolutions_Customer>
</modules>
<frontend>
<routers>
<!-- This is the frontname to override
EG: http://mydomainname.com/customer/ -->
<customer>
<args>
<modules>
<!-- Use the module Spinonesolutions_Customer BEFORE Mage_Customer -->
<Spinonesolutions_Customer before="Mage_Customer">Spinonesolutions_Customer</Spinonesolutions_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
AccountController.php:
<?php
/**
* Override Customer AccountController
*
* Override the createPost action
*
* @category Mage
* @package Mage_Customer
* @author Will Wright
*/
/*Controllers aren't included automatically, so we include it here so that we can extend it*/
include_once("Mage/Customer/controllers/AccountController.php");
class Spinonesolutions_Customer_AccountController extends Mage_Customer_AccountController {
public function createPostAction() {
die('here');
}
}
That’s it! You should now have a working override.
2 Comments for Magento Controller Override
Colin | April 15, 2010 at 9:02 am
Leave a comment!
« Magento Partial Refund Amount Correction for Authorize.net


It should be noted that this method can also be used to add additional controllers within an existing module namespace, not just override existing controllers. An especially useful case is when creating admin controllers and not wanting to pollute the root namespace with your module name.