2

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.

3

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
  • I have changed my code as above but nothing is working..Can't override helper also. – Chandresh Aug 10 '15 at 13:28
  • Did you clear your cache? – Robbie Averill Aug 10 '15 at 18:32
  • Yes..currently cache is disabled... and i had cleared it many times. – Chandresh Aug 11 '15 at 5:16
  • Please check for the existence and format of your app/etc/modules/Mt_Quote2Sales/.xml file – Robbie Averill Aug 11 '15 at 5:21
  • In Mt_Quote2Sales.xml all thing is correct, still not working. And i am overriding Request.php file from Helper it is also not working. – Chandresh Aug 11 '15 at 6:20
0

in your RequestController.php controller file your require once will come like this

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

Your require_once is looking a bit funky. There is no need to specify community I believe.

The magento way:

if (!class_exists('Bobcares_Quote2Sales_RequestController', false)) {
    require_once Mage::getConfig()->getModuleDir('controllers', 'Bobcares_Quote2Sales') . '/RequestController.php';
}

Edit: Read the comments below for why you should absolutely make sure to add the second false parameter to the class_exists call

  • 1
    Don't use class_exists in Magento, it triggers the autoloader which throws an error if it does not find the class file. Instead, use Mage::helper('core')->isModuleEnabled('Bobcares_Quote2Sales') – Fabian Schmengler Aug 10 '15 at 9:50
  • Cool thanks, I use this all the time in my development without issue. Probably something custom in the autoloader which deals with this. – Luke Rodgers Aug 10 '15 at 9:56
  • Do you look at your system.log from time to time? ;) – Fabian Schmengler Aug 10 '15 at 9:57
  • Haha yep. I've even overridden the mageCoreErrorHandler to die instead of Mage::log :| – Luke Rodgers Aug 10 '15 at 9:58
  • 1
    @fschmengler the false second parameter stops the autoloader from kicking in when asking if the class exists – Robbie Averill Aug 10 '15 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.