2

Anyone have any idea why I can't rewrite the Mage_Page_Block_Html_Head block?

My config.xml file looks like this:

<config>
    <modules>
        <Mymodule_Robots>
            <version>0.1.0</version>
        </Mymodule_Robots>
    </modules>
    <global>
        <blocks>
            <page>
                <rewrite>
                    <html_head>Mymodule_Robots_Block_Html_Head</html_head>
                </rewrite>
            </page>
        </blocks>
    </global>
</config>

If I have an XML error in the file it shows up in the error log, so the file itself is being loaded in but it isn't overriding the Block.

My block looks like this (but I'm got getting any errors about it not being found or anything like that):

class Mymodule_Robots_Block_Html_Head extends Mage_Page_Block_Html_Head {
    public function __construct(){
        #nothing logging
        Mage::log('test');
    }
    /**
     *
     * Override robots link on certain pages.
     * @return string
     *
     */
    public function getRobots(){
        Mage::log('test');
        if (empty($this->_data['robots'])) {
            $this->_data['robots'] = Mage::getStoreConfig('design/head/default_robots');
        }
        return 'test'; // $this->_data['robots'];
    }
}

It's an older version of Magento: 1.5.1

1 Answer 1

0

It turned out that two other modules were also trying to override this block which is what was causing the issue. One of them wasn't doing anything so I could just remove it. To debug the other one I added the following to Mage_Page_Block_Html_Head

public function getRobots()
    {
        // logging here
        Mage::log(get_class($this));
        if (empty($this->_data['robots'])) {
            $this->_data['robots'] = Mage::getStoreConfig('design/head/default_robots');
        }
        return $this->_data['robots'];
    }

That told me that MagicToolbox_MagicZoomPlus_Block_Html_Head was also extending the Mage_Page_Block_Html_Head block.

So then it was just a matter of adding a dependency to my module file to make sure it's loaded before my module and can therefore be extended:

<config>
    <modules>
        <Mymodule_Robots>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <MagicToolbox_MagicZoomPlus />
            </depends>
        </Mymodule_Robots>
    </modules>
</config>

And then extending my block from MagicToolbox_MagicZoomPlus_Block_Html_Head rather than Mage_Page_Block_Html_Head.

My only concern is what would happen if I ever removed the MagicZoomPlus module but I guess that's why one has a staging server.

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.