0

I'm trying to override the Helper_Data of a thirdparty module. But for some reason it wont work.

app/etc/modules/My_CustomModule.xml

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

.

app/code/local/My/CustomModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_CustomModule>
            <version>0.1.1</version>
        </My_CustomModule>
    </modules>
    <global>
        <helpers>
            <onestepcheckout>
                <rewrite>
                    <data>My_CustomModule_Helper_Data</data>
                </rewrite>
            </onestepcheckout>
        </helpers>
    </global>
</config>

.

app/code/local/My/CustomModule/Helper/Data.php

<?php
    class My_CustomModule_Helper_Data extends Idev_OneStepCheckout_Helper_Data
    {   
        public function setCustomerComment($observer)
        {
          Mage::log(get_class($this), null, 'test.log');
          // REST OF PARENT FUNCTION I WANT TO OVERRIDE
        }
    }

I already added a Mage::log to the function I'm trying to override but this keeps returning the classname of the original function.

UPDATE:

I did some digging in the code and found out that the function setCustomerComment is called by the observer event. I have no idea what this exactly does and or this just simply overrules the override?

app/code/local/Idev/OneStepCheckout/etc/config.xml

<?php    
        <events>
            <checkout_type_onepage_save_order>
                <observers>
                    <onestepcheckout_save_customercomment>
                        <type>model</type>
                        <class>Idev_OneStepCheckout_Helper_Data</class>
                        <method>setCustomerComment</method>
                    </onestepcheckout_save_customercomment>
                </observers>
            </checkout_type_onepage_save_order>
            ...
        </events>

I also created a file "test.php" in the root of magento with the code:

test.php

<?php

include "app/Mage.php";
Mage::app();

$customerHelper = Mage::helper('onestepcheckout/data');
var_dump(get_class($customerHelper));

This returns the module I have created, so it should override the initial class and functions right?

Any help would be appreciated.

5
  • Did your custom module appears as "Enable" in your BO (system > configuration> Advanced > Advanced) ?
    – Kozame
    Nov 15, 2017 at 14:33
  • Yes it does, the module is active.
    – Myron
    Nov 15, 2017 at 15:16
  • Do you flush the cache ? How do you call you setCustomerComment function in your code ?
    – Kozame
    Nov 15, 2017 at 15:21
  • Also flushed the cache. The function is run after the order is placed in magento (frontend).
    – Myron
    Nov 16, 2017 at 12:10
  • @Kozame please check my above question, i've added some research regarding your question: > How do you call you setCustomerComment function in your code ?
    – Myron
    Jan 4, 2018 at 13:12

2 Answers 2

0

Declaration of your helper class is wrong. please check below code.

app/code/local/My/CustomModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_CustomModule>
            <version>0.1.1</version>
        </My_CustomModule>
    </modules>
    <global>
        <helpers>
            <custommodule> <!-- change here -->
                <class>My_CustomModule_Helper</class>
            </custommodule> <!-- change here -->
            <onestepcheckout>
                <rewrite>
                    <data>My_CustomModule_Helper_Data</data>
                </rewrite>
            </onestepcheckout>
        </helpers>
    </global>
</config>
1
  • This didn't do the trick unfortunately. Thanks for the response.
    – Myron
    Nov 16, 2017 at 12:09
0

Here is an example if you want to override Mage_Checkout_Helper_Data

app/etc/modules/My_Custommodule.xml

<?xml version="1.0"?>
<config>
  <modules>
    <My_Custommodule>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </My_Custommodule>
  </modules>
</config>

app/code/local/My/Custommodule/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <My_Custommodule>
      <version>0.1.0</version>
    </My_Custommodule>
  </modules>
  <global>
    <helpers>
        <custommodule>
          <class>My_Custommodule_Helper</class>
        </custommodule>
        <checkout>
                <rewrite>
                    <data>My_Custommodule_Helper_Checkout_Data</data>
          </rewrite>
        </checkout>
    </helpers>
  </global>
</config> 

app/code/local/My/Custommodule/Helper/Data/Data.php

<?php
class My_Custommodule_Helper_Data extends Mage_Core_Helper_Abstract
{

}

app/code/local/My/Custommodule/Helper/Checkout/Data.php

<?php
class My_Custommodule_Helper_Checkout_Data extends Mage_Checkout_Helper_Data
{

}

app/code/local/My/Custommodule/Helper/Checkout/Data.php overriding Mage_Checkout_Helper_Data

4
  • Thanks for the answer, but this does not explain what i'm doing wrong.
    – Myron
    Nov 15, 2017 at 15:13
  • does it make any difference if i have "Module" in the module name My_CustomModule in uppercase? or should it be (like your example) in lowercase?
    – Myron
    Nov 20, 2017 at 9:56
  • yes, some time it create issues I would prefer My_Custommodule instead of My_CustomModule Nov 20, 2017 at 10:04
  • @Myron : you can check with stackoverflow.com/questions/11547151/… Nov 20, 2017 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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