As far as I know, this is not at all possible with magento. Basically what you need is to inherit your class from HelperA
(of module A) and HelperB
(of module B).
In php, you cannot extend a class from two base classes
So if you really need to extend from HelperA
and HelperB
at the same time, then the best shot would be..
Extend your your Helper
from HelperA
and then rewrite HelperA
class in such a way that it extends from HelperB
instead of default base class Mage_Core_Helper_Abstract
OR
Extend your your Helper
from HelperB
and then rewrite HelperB
class in such a way that it extends from HelperA
instead of default base class Mage_Core_Helper_Abstract
.
This way your Helper
will extend from both HelperA
and HelperB
. Which method should opt in this case is purely depends upon your application. So choose the right option. Here I am going to show you how to do the first implementation.
File : app/code/local/Namespace/Module/etc/config.xml
<config>
<global>
<helpers>
<!-- your module's helper definition -->
<namespace_module>
<class>Namespace_Module_Helper_Data</class>
</namespace_module>
<!-- this part rewrites helperA class -->
<helperA_alias_name>
<rewrite>
<data>Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data</data>
</rewrite>
</helperA_alias_name>
</helpers>
</global>
</config>
File : app/code/local/Namespace/Module/Helper/Data.php
<?php
class Namespace_Module_Helper_Data
extends Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
{
//your helper method should come here.
}
File : app/code/local/Namespace/Module/Helper/Rewrite/NamespaceA/ModuleA/Helper/Data.php
<?php
class Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
extends NamespaceB_ModuleB_Helper_Data
{
//you need to paste every single method of HelperB here.
}
Explanation
Here Namespace_Module
stands for your module. NamespaceA_ModuleA
stands for MODULE A
and NamespaceB_ModuleB
stands for MODULE B
.
Your module's config.xml
file holds two important definitions. First it defines your modules helper class Namespace_Module_Helper_Data
. Secondly, it rewrites HelperA
with a custom class Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
. This way magento will use Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
class when a request for helper class of MODULE A
get processed.
Now see the class definitions. Firstly, your helper class extends Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
. This means your class is now inheriting Helper A
. Secondly Namspace_Module_Helper_Rewrite_NamespaceA_ModuleA_Helper_Data
extends from HelperB
. Due to this now your helper class inherit from HelperB
too.
ie Your helper class inherits from HelperA
which then inherits from HelperB
.
This is purely theory. I didn't try this before. But it seems really logical for me.
Note 1 : Use this approach only in the case, if you really want to define only one class which should extend from two base classes. Otherwise you can go for @Rick Method.
Note 2 : For the proper working of your module, you need to make sure two things here. First, your module should load only after MODULE A
and MODULE B
. Second, MODULE B
should load before MODULE A
. That is the order of loading should be..
MODULE B - first
MODULE A - second
YOUR MODULE - third
Good luck