Magento block override from two different modules

心已入冬 提交于 2019-12-07 10:29:13

问题


Hi I have some issues in overriding a magento core block. In my module I need to override Mage_Catalog_Block_Navigation

<blocks>
  <catalog>
    <rewrite>
            <navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
        </rewrite>
  </catalog>
</blocks>

but this is already overridden by another magento extension from another company:

<blocks>
  <catalog>
    <rewrite>
        <navigation>Othercompany_Othermodule_Block_Navigation</navigation>
    </rewrite>
  </catalog>
</blocks>

Both extension overrides different methods and they don't know abut each other, but magento reads the second company overrides and not my. I don't want to use module dependencies. Is there any way to not break the two extensions functionality.


回答1:


Yes, you have to decide which one officially overwrites the core Block. Have that one inherit the one that isn't doing the override, and have that one inherit the core one.

My_Custom_Block extends Other_Custom_Block
Other_Custom_Block extends Mage_Core_Block
Mage_Core_Block extends Whatever_Magento_Wants

Edit the config.xml files so that only My_Custom_Block is the one that is overriding the core Block.

EDIT Here's the XML you need:

<blocks>
  <catalog>
    <rewrite>
            <navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
        </rewrite>
  </catalog>
</blocks>



回答2:


Thx Max. I think, like your example, that the "My_Custom_Block" should be the last hierarchic class, so you don't touch anythings in "Other_Custom_Block" class.

Then you have only to comment the rewrite rule in "Other Company" config.xml.



来源:https://stackoverflow.com/questions/9311828/magento-block-override-from-two-different-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!