Magento – Override community extension controller is not working in magento 1.9.2

extensionsmagento-1.9

I am using Quote2Sales community extension, but i need some customization in it so i am overriding controller by local module.

In Community folder Bobcares package and in this Quote2Sales extension.

To override RequestController.php i have made Mt package inside local and in it Quote2Sales folder. In it controllers and make file RequestController.php . In RequestController.php code is as following:

require_once 'Bobcares/Quote2Sales/controllers/RequestController.php';

class Mt_Quote2Sales_RequestController extends Bobcares_Quote2Sales_RequestController {
---
---
}

And in etc folder config.xml file code is as following:

<?xml version="1.0"?>
<config>
    <modules>
        <Mt_Quote2Sales>
            <version>0.0.1</version>
        </Mt_Quote2Sales>
    </modules>
    <frontend>
        <routers>
            <quote2sales>
                <use>standard</use>
                <args>
                    <modules>
                        <mt_quote2sales before="Bobcares_Quote2Sales">Mt_Quote2Sales</mt_quote2sales>
                    </modules>
                </args>
            </quote2sales>
        </routers>
    </frontend>
    <global>
        <helpers>
            <quote2sales>
                <class>Mt_Quote2Sales_Helper</class>
            </quote2sales>
        </helpers>
    </global>
</config>

And also add code in Mt_Quote2Sales.xml as follow:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mt_Quote2Sales>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Bobcares_Quote2Sales/>
            </depends>
        </Mt_Quote2Sales>
    </modules>
</config>

But it is not working. Please help me.

Best Answer

You should ensure that you have your module registration XML in app/etc/modules/Mt_Quote2Sales.xml, which should tell Magento that your module exists and is on the local code pool.

Second, you should tell Magento in that file that it should depend on your community module. This will immediately help by ensuring that it is loaded after the community module (which makes sense, because you're extending it). An example of this XML file might be:

# File: app/etc/modules/Mt_Quote2Sales.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mt_Quote2Sales>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Bobcares_Quote2Sales />
            </depends>
        </Mt_Quote2Sales>
    </modules>
</config>

Third, as the others have mentioned already, remove the community component from your require path - include paths are not code pool specific, essential when extending controllers, which don't follow the autoloader's convention:

require_once 'Bobcares/Quote2Sales/controllers/RequestController.php';

class Mt_Quote2Sales_RequestController extends Bobcares_Quote2Sales_RequestController
{

}

Lastly, if it is still not working, you should create a simple frontAction which dumps out something and load it in the browser. If your XML is configured correctly, you might have a conflict with another module.

Make sure you clear or disable your cache.

Edit

I've just seen that you've posted your attempt to rewrite a helper - unlike the controller configuration where you can just tell Magento that your controller should be loaded before the one you're extending, with models/helpers/blocks you need to rewrite the path for it:

# File: app/code/local/Mt/Quote2Sales/etc/config.xml
...
<global>
    <helpers>
        <quote2sales>
            <rewrite>
                <data>Mt_Quote2Sales_Helper_Data</data>
            </rewrite>
        </quote2sales>
    </helpers>
</global>
...

You can test this using magerun (if you have it), or with a simple ad hoc script like so:

# File ./test.php
<?php
require_once 'app/Mage.php';
Mage::app();

$test = Mage::helper('quote2sales');
var_dump(get_class($test)); // Mt_Quote2Sales_Helper_Data if you're configured correctly
Related Topic