1

I'm planning to extend a community extension by creating relevant files in app/code/local/myname/myext. The community extension has multiple files that I want to customise but let's start simply. How would I implement the local equivalent of Helper/Data.php, even just to show it's working?

For example the community extension is like

class Compasser_Diogenes_Helper_Data extends Mage_Payment_Helper_Data
{
    //
    public function startDiogenes($cId, $stId, $shId, $mCode)
    {
        // working code is here, can output to log files

My local file is just trying to prove it's getting called. app/code/local/Kaska/Diogenesext/Helper/Data.php

include_once 'Compasser/Diogenes/Helper/Data.php';
// I also tried require_once Mage::getConfig()->getModuleDir('Helper', 'Diogenes') . '/Data.php';

class Kaska_Diogenesext_Helper_Data extends Compasser_Diogenes_Helper_Data
{

    public function startDiogenes($cId, $stId, $shId, $mCode)
    {

        Mage::log('test', null, 'test.log');

This is app/code/local/Kaska/Diogenesext/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Kaska_Diogenesext>
        <version>0.0.1</version>
    </Kaska_Diogenesext>
</modules>
<global>
    <helpers>
        <kaska_diogenesext>
            <rewrite>
                <data>Kaska_Diogenesext_Helper</data>
            </rewrite>
        </kaska_diogenesext>
    </helpers>

This is the what's in the app/etc/modules/Kaska_Diogenesext.xml file. It's showing as enabled in admin.

<?xml version="1.0"?>
<config>
<modules>
    <Kaska_Diogenesext>
        <active>true</active>
        <codePool>local</codePool>
        <depends>
            <Compasser_Diogenes></Compasser_Diogenes>
        </depends>
    </Kaska_Diogenesext>
</modules>

In my log files I just see the community extension working, there's nothing from the local extension, nothing in test.log and no errors either. Cache not enabled but flushed anyway.

1

There is no need to include the helper from Compasser because helpers are autoloaded (you have to include only controllers if you like to extend them). Also in your config.xml please try to change <kaska_diogenesext> to <compasser_diogenes> and <data>Kaska_Diogenesext_Helper</data> to <data>Kaska_Diogenesext_Helper_Data</data>.

3

In addition to the other answers that cover your syntax errors:

Something that is often overlooked: If you don't want to break translations of the module, be sure to make the module name explicit, otherwise it is automatically detected based on the class name and Magento will try to load translations from your own module instead of from the original. This will result in missing translations in developer mode and can result in translation conflicts in production.

To do so, simply add the following line to your rewritten helper:

protected $_moduleName = 'Kaska_Diogenesext';

where Kaska_Diogenesext is the name of the original extension, as in its class names.

1

There are some mistake you have doing in code:

  • Class rewrite is not proper. In tag kaska_diogenesext is wrong,it should be Compasser_Diogenes module helpers class prefix identifier .

For getting Compasser_Diogenes helper classes prefix /identifier ,you need goto Compasser/Diogenes/etc/config.xml.Here you can find helper between tag.

<global>
    <helpers>
        <diogenes> <!-- i Guss that Compasser_Diogenes helper prefix/ identifer is diogenes -->
                <class>Compasser_Diogenes_Helper</class>
        </diogenes>
    </helpers>
    .....

Now Final is app/code/local/Kaska/Diogenesext/etc/config.xml

<global>
......
    <helpers>
        <diogenes> <!--  kaska_diogenesext  change to  diogenes -->
            <rewrite>
                <data>Kaska_Diogenesext_Helper</data>
            </rewrite>
        </diogenes>
    </helpers>
  • As it have rewrite helper class ,you does not need to include the parent class().Magento auto loader automatically include Compasser/Diogenes/Helper/Data.php;So delete include_once 'Compasser/Diogenes/Helper/Data.php';
  • Thanks for the detailed answer. I had to tweak it a bit to get it right - Kaska_Diogenesext_Helper_Data (as per Michael's answer below) – Michael Sep 20 '15 at 18:58
0

Here i am show you how to Extend community Or third party module helper class in your own modules. Now here i am extend asmaty extension helper.

  1. create your module register xml app/etc/modules/Myextend_Shopbyextend.xml

    <?xml version="1.0"?> <config> <modules> <Myextend_Shopbyextend> <active>true</active> <codePool>local</codePool> <depends> <Amasty_Shopby /> </depends> </Myextend_Shopbyextend> </modules> </config>

  2. create module config.xml file app/code/local/Myextend/Shopbyextend/etc/

<?xml version="1.0"?> <config> <modules> <Myextend_Shopbyextend> <version>0.1.0</version> </Myextend_Shopbyextend> </modules> <global> <helpers> <shopbyextend> <class>Myextend_Shopbyextend_Helper</class> </shopbyextend> <amshopby> <rewrite> <data>Myextend_Shopbyextend_Helper_Data</data> </rewrite> </amshopby> </helpers>
</global> </config>

  1. Last create your help file app/code/local/Plumtree/Shopbyextend/Helper/Data.php and extends Amasty_Shopby_Helper_Data class

class Plumtree_Shopbyextend_Helper_Data extends Amasty_Shopby_Helper_Data { public function getCurrentCategory() { \\ Write your code here } }

I hope this will help you

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.