1

I need to override a Block from an external extension. This is my setup with the necessary files:

The module file (app/etc/modules/Mynamespace_Mymodulename.xml):

<?xml version="1.0"?>
<config>
  <modules>
    <Mynamespace_Mymodulename>
      <active>true</active>
      <codePool>local</codePool>
      <depends>
        <mgs_auction />
      </depends>
    </Mynamespace_Mymodulename>
  </modules>
</config>

The config file (app/code/local/Mynamespace/Auction/etc/config.xml):

<?xml version="1.0"?>
<config>
  <modules>
    <Mynamespace_Mymodulename>
      <version>1.0</version>
    </Mynamespace_Mymodulename>
  </modules>
  <global>
    <blocks>
        <auction>
          <rewrite>
            <auction>Mynamespace_Auction_Block_Auction</auction>
          </rewrite>
        </auction>
    </blocks>
  </global>
</config>

The block path from the extension:

app/code/local/Mgs/Auction/Block/Auction.php

and my structure:

app/code/local/Mynamespace/Auction/Block/Auction.php

with following content:

class Mynamespace_Auction_Block_Auction extends Mgs_Auction_Block_Auction {
    public function ... () {
        ...
    }
}

Tested it but the original block class from the extension is still used. I guess something is missing or wrong titled in the config.xml. Could you help me out?

Edit:

The original config.xml from the extension:

<?xml version="1.0"?>
<config>
    <modules>
        <Mgs_Auction>
            <version>2.2.0</version>
        </Mgs_Auction>
    </modules>
    ...
   <global>
        <blocks>
            <auction>
                 <class>Mgs_Auction_Block</class>
            </auction>
        </blocks>
   </global>
</config>
3
  • Could you post the original module config.xml file ? Commented Jul 6, 2016 at 11:11
  • Hi @Raphael. Is there a specific part that you like to see? It's a huge file and i don't know if everything is necessary.
    – jbl90
    Commented Jul 6, 2016 at 11:50
  • 1
    @Raphael I added a part from the config.xml of the extension
    – jbl90
    Commented Jul 6, 2016 at 13:28

3 Answers 3

2

I reckon you need to respect the case, for example in your app/etc/modules XML file you should replace:

<mgs_auction />

With:

<Mgs_Auction />

On top of that your block is not properly placed and declared.

Indeed you declared your module as Mynamespace_Mymodulename but your block is declared under app/code/local/Mynamespace/Auction/Block/Auction.php whereas it should be app/code/local/Mynamespace/Mymodulename/Block/Auction.php

On top of that ensure your module is in the app/code/local/Mynamespace/Mymodulename folder and change the following in your config.xml :

  <global>
    <blocks>
        <auction>
          <rewrite>
            <auction>Mynamespace_Auction_Block_Auction</auction>
          </rewrite>
        </auction>
    </blocks>
  </global>

With:

  <global>
    <blocks>
        <auction>
          <rewrite>
            <auction>Mynamespace_Mymodulename_Block_Auction</auction>
          </rewrite>
        </auction>
    </blocks>
  </global>
1
  • 1
    Thanks again for your great help! Your solution did the job. As addition, of course i also had to changed the class name to: Mynamespace_Mymodulename_Block_Auction
    – jbl90
    Commented Jul 6, 2016 at 13:55
2

You can just set your class to extend the class you are trying to override:

class Mynamespace_Auction_Block_Auction extends Mgs_Auction_Block_Auction

Set your layout update xml in config.xml file

<frontend>
    ...
    <layout>
        <updates>
            <mymodule>
                <file>mymodule.xml</file>
            </mymodule>
        </updates>
    </layout>
    ...
</frontend>

and remove in mymodule.xml layout, origin block and replace on your block for example.

<module_controller_action>
  <reference name='content'>
     <remove name='oldblock' />
     <block type="your_namespace/your_type" name="oldblock" template="oldblock.phtml">
  </reference>
</module_controller_action>
1
  • Hello @Naumov. Thanks for your help but I don't know if this would fix my problem. I need to override a function in the block class called "Auction.php".
    – jbl90
    Commented Jul 6, 2016 at 13:34
1

Rewrites are tricky. There are several options what could go wrong. As a first guess - in the config.xml, in rewrite section, in path global->blocks->rewrite->auction - maybe should be the mgs_auction, as I presume that this is the name module is called. To check what this tag should be, check Msg Auction's (module you're rewriting) config.xml, the section where it declares blocks:

<global> <blocks> <the_needed_name_is_here> </the_needed_name_is_here> </blocks> </global>

If this doesn't help, check that this block is used, because if it is it's child, then the rewrite don't work, as I am sure you are aware of.

1
  • Hello @Wladyslaw. Thanks for your help. I tryed your proposal but no luck. I've added a part of the original config.xml. Maybe you have another clue.
    – jbl90
    Commented Jul 6, 2016 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.