问题
I'm trying to override in the local folder a module which is in the local folder also, but I don't know if it's possible. This is what I've done.
I've created /local/Mycompany/Modulename/Model/Model.php which i'd like to override the /local/Othercompany/Modulename/Model/Model.php
my model.php is:
class Mycompany_Modulename_Model_Model extends Othercompany_Modulename_Model_Model
{ ... }
and my config.xml
<global>
<models>
<othercompanymodulename>
<rewrite>
<model>Mycompany_Modulename_Model_Model</model>
</rewrite>
</othercompanymodulename>
</models>
The class is been instantiated whith Mage::getModel('othercompanymodulename/model')
My Mycompany_Mymodule.xml
<config>
<modules>
<Mycompany_Modulename>
<active>true</active>
<codePool>local</codePool>
<depend>
<Othercompany_Modulename/>
</depend>
</Mycompany_Modulename>
</modules>
But my module is ignored. Is possible to override in local folder a class located also in local folder? What I'm doing wrong?
回答1:
open your [magento]\app\etc\modules\Mycompany_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Modulename>
<active>true</active>
<codePool>local</codePool>
<depends>
<Othercompany_Modulename/>
</depends>
</Mycompany_Modulename>
</modules>
</config>
above code force Othercompany_Modulename
to load first.
hope this help you
回答2:
If i'm right you missed an underscore in the definition of the overwritten model in your config.xml:
<global>
<models>
<othercompany_modulename>
<rewrite>
<model>Mycompany_Modulename_Model_Model</model>
</rewrite>
</othercompany_modulename>
</models>
</global>
回答3:
It's probably an extension conflicts.
How to check and resolve:
- Check extension are conflicted with this free magento module: http://www.magentocommerce.com/magento-connect/modules-conflict-detector.html
- Locate conflicted extension and use one solution for resolve (read bottom "How do I resolve conflicts?")
- Clear cache
How do I resolve conflicts? You have 3 choices for resolving conflicts:
- Merge the code from one conflicting file into another and switch off the rewrite config.xml in one
- Switch off the rewrite in one config.xml and then make the conflicting extension PHP file extend the other extension
- Use the capability to make one extension depend on another. They will then rewrite in that order
Read more: http://www.webshopapps.com/blog/2010/11/resolving-magento-extension-conflicts/ Related: Magento - Model Override Not Working in local codePool
来源:https://stackoverflow.com/questions/22942050/magento-how-to-override-a-model-in-a-local-module