Magento 1.9 – Overriding Block Class from Extension

blocksmagento-1.9moduleoverrides

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>

Best Answer

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>
Related Topic