Magento 1.4 Extensions – How to Extend a Core Helper vs. Copying to Local

extensionshelpermagento-1.4

I have extended a Magento core class (i.e. Model) but am not sure how to extend a core Helper. The documentation varies and I have not found anything that works.

Currently I want to extend this Helper class:

app/code/core/Mage/Catalog/Helper/Category.php

And the "hack" (though perfectly legal) is to copy the entire class to here:

app/code/local/Mage/Catalog/Helper/Category.php

I would, however, prefer to EXTEND that class so my code was more portable, so I had this file:

app/code/local/Mycompany/Catalog/Helper/Category.php

with this class:

class Mycompany_Catalog_Helper_Category extends Mage_Catalog_Helper_Category{
    .. etc..
}

How would I do this?

By the way, irritatingly enough, there appears to be a great tutorial on this but the critical XML information is missing!! If anyone can fill that in and post here, I'll back-reference it for everyone's benefit:

https://www.thirdandgrove.com/extending-magento-core-classes

Best Answer

You can extend the class, the missing piece of the puzzle is to add an entry into your etc/config.xml

<config>
    ...
    <global>
        ...
        <helpers>
            <catalog>
                <rewrite>
                    <category>Mycompany_Catalog_Helper_Category</category>
                </rewrite>
            </catalog>
        </helpers>
        ...
    </global>
   ...
</config>

This will tell Magento to override the catalog/category helper, so the call Mage::helper('catalog/category') will return your class.

Related Topic