Magento block override from two different modules

2019-05-07 16:55发布

问题:

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.