Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Override methodology
 
lbourrel
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-09
Ayaline - Poitiers
 

Hi everybody,

I have a methodology question about extensions.

- I have an extension E1 overriding the model M.
- I have an other extension E2 overriding the same model M.

It could be a controller instead of Model, the problem is the same.

I guess i will have a conflict between these extensions. What are your advices ?
- do just one extension
- create a third extension that contains the common part ?

Thanks
Laurent

 
Magento Community Magento Community
Magento Community
Magento Community
 
crius
Guru
 
Avatar
Total Posts:  623
Joined:  2007-10-16
Denmark
 

Yeah, this is definitely a problem. We have discussed it a little before:

http://www.magentocommerce.com/boards/viewthread/11257/

You need to hack the extensions manually to fix it. If the two extensions of class M do not conflict, you can change the inheritance of one of the extension classes, so you have something like class E2 extends E1 and class E1 extends M. Of course, you can also merge the two files into one as you are suggesting. Both solutions are ugly. Unfortunately, I don’t think a beautiful solution exists.

I think we should also use the event-observer method as much as possible to avoid overriding classes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
piotrn
Member
 
Total Posts:  33
Joined:  2008-04-27
 

If you will have two modules, that rewrite the same original module,
the last module loaded will take an effect.

It’s because the later module “rewrite\” declaration will overwrite any previous “rewrite\” of given original module.
So only the last “rewrite\” loaded has any effect.

Modules from your namespace will be loaded in order they appear in your Namespace_All.xml file.
Only way to control the order besides that, is using <depends><Module /></depends>.

In your example it would look like this:

<config>
<
modules>

<
NS_E1>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
                <
Mage_OriginalModuleName/>
            </
depends>
</
NS_E1>
<
NS_E2>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
               <
NS_E1 />
            </
depends>
</
NS_E2>
</
modules>
</
config>

Now simply make sure that E2 extends E1.
Voila, now you can use both E2 and E1 methods, and if E2 is disabled or not installed, E1 will still work.

If you don’t want to extend E1 in E2, you can simply use your E1 module model. You will need to instantiate it your self.
Calling

Mage:getModel("module/model");
will always get you E2 instantiation, but you can use
Mage:getModel("NS_E1_Model_Class_Name");
in this case, Magento will try to load specified class.

Naturraly, this work only until your user will not install 3rd module overriding OriginalModule smile But for that i don’t have a workaround yet.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lbourrel
Jr. Member
 
Avatar
Total Posts:  26
Joined:  2008-06-09
Ayaline - Poitiers
 

Hi,

Thanks for your comments.

Anders,
i agree with you : using events is the better way. But it’s not always possible, so we’ll have to do ugly things cheese

Piotr,
I didn’t know you could load model with just the class name. It’s a good way for technical extensions (such as import for exemple) that don’t impact the whole shop.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top