Magento – How to rewrite a class that has already been rewritten

blocksconfigurationoverrides

Update: I found that the class I actually need to rewrite is SMDesign_SMDZoom_Block_Product_View_Media and not SMDesign_ColorswatchProductView_Block_Product_View_Media like I originally thought. However, the exact same issue still applies.

The SMDesign SMDZoom extension rewrites block class 'catalog/product_view_media'. The xml for that looks like this:

       <global>
    ...         
       <blocks>
        <smdzoom>
            <class>SMDesign_SMDZoom_Block</class>
        </smdzoom>
    </blocks>
    <blocks>
        <catalog>
            <rewrite>
                <product_view_media>SMDesign_SMDZoom_Block_Product_View_Media</product_view_media>
            </rewrite>
        </catalog>
    </blocks>
           ....
       </global>

I want to rewrite this class again. I want to rewrite the catalog/product_view_media class that this smdzoom module is rewriting. Can this be done? What would the config xml look like in my module to do this?

Currently this is my module init xml file:

<config>
    <modules>
        <Goorin_SMDZoom>
            <active>true</active>
            <codePool>local</codePool>
        </Goorin_SMDZoom>
        <depends>
            <Mage_Catalog />
            <SMDesign_SMDZoom />
        </depends>
    </modules>
</config>

and the module config.xml file:

<global>
        <blocks>
            <gbismdzoom>
                <class>Goorin_SMDZoom_Block</class>
            </gbismdzoom>
            <catalog>
                <rewrite>
                    <product_view_media>Goorin_SMDZoom_Block_Product_View_Media</product_view_media>
                </rewrite>
            </catalog>
        </blocks>
    </global>

My new class simply looks like this for testing:

class Goorin_SMDZoom_Block_Product_View_Media extends SMDesign_SMDZoom_Block_Product_View_Media
{
    public function _construct() {
        parent::_construct();
    }
}

I'm testing this by displaying template path hints, and I'm seeing SMDesign block still being used on the product view page. What am I doing wrong?

Best Answer

I put the <depends> node in the wrong location in my module's init xml file. It must be nested within the module name's node, like so:

<config>
    <modules>
        <Goorin_SMDZoom>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
                <SMDesign_SMDZoom />
            </depends>
        </Goorin_SMDZoom>
    </modules>
</config>
Related Topic