I am trying to override an Ajax controller in Magento community module. The problem is that my controller gets called only if the method doesn’t exist. I can’t override any of the overridden controller methods.
Here is my code
config.xml:
<frontend>
<routers>
<overriden_module>
<args>
<modules>
<My_Module before="Overriden_Module">My_Module</My_Module>
</modules>
</args>
</overriden_module>
</routers>
</frontend>
I am overriding an ajax controller so – AjaxController.php :
<?php
require_once (Mage::getModuleDir('controllers', 'Overriden_Module') . DS .'AjaxController.php');
class My_Module_AjaxController extends Overriden_Module_AjaxController {
//This is an overridden method and no hit
public function streetAction() {
die('FOO');
}
// This action is not overridden and gets called
public function otherAction(){
die('BAR')
}
}
As requested this is the router part from the module I’m overriding:
<routers>
<module_name>
<use>standard</use>
<args>
<module>Module_name</module>
<frontName>frontname</frontName>
</args>
</module_name>
<checkout>
<args>
<modules>
<Module_Name before="Mage_Checkout">Module_Name_Checkout</Module_Name>
</modules>
</args>
</checkout>
</routers>
Thank you.
Ok after some debugging i found out what was causing the issue.
The module i’m rewriting was also defining admin router with the same name as the frontend one. When Magento searches for a router match to dispatch it will first check the admin routers and therefore running the admin controller of the module and not even checking the front routers.
If you dump
$this->_routersin the code bellow you will see what i’m talking about.app/code/core/Mage/Core/Controller/Varien/Front.php line 174:So the answer is to simply override the admin controller