1

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

1 Answer 1

7

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.

1
  • Amazing how simple things are when you have the right information. Thanks! I'm back-updating that post so everyone can reference this. Commented Jun 17, 2016 at 22:16

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.