Magento Asked by Myron on December 19, 2020
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.
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>
Answered by Abhishek Panchal on December 19, 2020
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
Answered by Chander Shekhar on December 19, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP