Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Error when overriding Helper Class Mage_Catalog_Helper_Data
 
Husky
Jr. Member
 
Total Posts:  19
Joined:  2008-07-27
 

Hi!

when i override the following Helper class I get an error in the backend system.
It seems like the translation is not working for that module any more.

Any ideas??

<helpers>
        <
chairconfig>
            <class>
MyCompany_Module_Helper</class>
        </
chairconfig>
    
        <
catalog>
            <
rewrite>
                <
data>MyCompany_Module_Helper_Data</data>    
            </
rewrite>
        </
catalog>
    
        
    </
helpers>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Husky
Jr. Member
 
Total Posts:  19
Joined:  2008-07-27
 

Any ideas????

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

I have the same problem - did you find what was wrong?

Thanks,
Michael

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

As it turns out the problem is that during the translation, magento determines the module name by looking at the class name unless the $_moduleName variable is defined. When we override the helper class, the classname is obviously different and magento gets the wrong module name.

The solution is simply to include:

protected $_moduleName "Mage_Contacts";

(example for contacts - replace with whatever module the overridden class is in) in your class so that the translation function will get the module name from there instead of trying to get it from the class name.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mathmax
Member
 
Total Posts:  44
Joined:  2008-09-21
 

I don’t understand the config.xml file. Could you explain me how to override an helper class ? I would like to override Mage_Core_Helper_Abstract.
Thanks.

Regards,

mathmax

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

You need a config.xml file that looks something like:

<?xml version="1.0"?>
<config>
    <
modules>
        <... 
module name here ...>
            <
version>0.1.0</version>
        </ ... 
module name here ...>
    </
modules>
    <global>
        <
helpers>
                <
core>
                   <
rewrite>
                        <abstract>
ModuleName_Core_Helper_Abstract</abstract>
                   </
rewrite>
                </
core>
        </
helpers>
    </global>
</
config>

Your code should extend Mage_Core_Helper_Abstract.

Try this and let me know if is doesn’t work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

I do apologize for my post which is misleading. The class you are trying to extend is an abstract class and as far as I know there is no way to rewrite an abstract class. You must override the classes that extend the abstract.

mpikounis - 25 March 2009 11:10 PM

You need a config.xml file that looks something like:

<?xml version="1.0"?>
<config>
    <
modules>
        <... 
module name here ...>
            <
version>0.1.0</version>
        </ ... 
module name here ...>
    </
modules>
    <global>
        <
helpers>
                <
core>
                   <
rewrite>
                        <abstract>
ModuleName_Core_Helper_Abstract</abstract>
                   </
rewrite>
                </
core>
        </
helpers>
    </global>
</
config>

Your code should extend Mage_Core_Helper_Abstract.

Try this and let me know if is doesn’t work.
 
Magento Community Magento Community
Magento Community
Magento Community
 
mathmax
Member
 
Total Posts:  44
Joined:  2008-09-21
 

Thank you for your answer.

It would be too difficult to override all concrete classes:

Search “extends Mage_Core_Helper_Abstract” (65 hits in 65 files)
C:\wamp\www\app\code\core\Mage\Adminhtml\Helper\Catalog.php (1 hits)
C:\wamp\www\app\code\core\Mage\Adminhtml\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Adminhtml\Helper\Rss.php (1 hits)
C:\wamp\www\app\code\core\Mage\AdminNotification\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Api\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Backup\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Bundle\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Catalog\Helper\Category.php (1 hits)
C:\wamp\www\app\code\core\Mage\Catalog\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Catalog\Helper\Image.php (1 hits)
C:\wamp\www\app\code\core\Mage\Catalog\Helper\Map.php (1 hits)
C:\wamp\www\app\code\core\Mage\Catalog\Helper\Output.php (1 hits)
C:\wamp\www\app\code\core\Mage\CatalogInventory\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\CatalogRule\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\CatalogSearch\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Checkout\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Cms\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Cms\Helper\Page.php (1 hits)
C:\wamp\www\app\code\core\Mage\Contacts\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Core\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Core\Helper\Http.php (1 hits)
C:\wamp\www\app\code\core\Mage\Core\Helper\Js.php (1 hits)
C:\wamp\www\app\code\core\Mage\Core\Helper\String.php (1 hits)
C:\wamp\www\app\code\core\Mage\Core\Helper\Url.php (1 hits)
C:\wamp\www\app\code\core\Mage\Cron\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Customer\Helper\Address.php (1 hits)
C:\wamp\www\app\code\core\Mage\Customer\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Dataflow\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Directory\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Downloadable\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Downloadable\Helper\Download.php (1 hits)
C:\wamp\www\app\code\core\Mage\Downloadable\Helper\File.php (1 hits)
C:\wamp\www\app\code\core\Mage\Eav\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Giftcert\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\GiftMessage\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\GoogleAnalytics\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\GoogleBase\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\GoogleCheckout\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\GoogleOptimizer\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Install\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Log\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Newsletter\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Page\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Page\Helper\Html.php (1 hits)
C:\wamp\www\app\code\core\Mage\Paygate\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Payment\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Paypal\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\PaypalUk\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Poll\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Rating\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Reports\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Review\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Rss\Helper\Catalog.php (1 hits)
C:\wamp\www\app\code\core\Mage\Rss\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Rss\Helper\Order.php (1 hits)
C:\wamp\www\app\code\core\Mage\Rule\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\SalesRule\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Sendfriend\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Shipping\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Sitemap\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Tag\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Tax\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Usa\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Weee\Helper\Data.php (1 hits)
C:\wamp\www\app\code\core\Mage\Wishlist\Helper\Data.php (1 hits)

I’ll have to modify the sources of Mage_Core_Helper_Abstract…

Thanks.

Best regards.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

May I ask what it is you want to do that needs to be in the default helper class of all these classes? Can you not just add a generic helper class that you reference from everywhere needed?

Cheers,
Michael

 
Magento Community Magento Community
Magento Community
Magento Community
 
mathmax
Member
 
Total Posts:  44
Joined:  2008-09-21
 

No because I would like to change the behavior of htmlescape() and I would like all existing htmlescape() calls to go through this modified function.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

I see. Just keep in mind that you will have to re-apply the hack every time you update. This is a major drawback of magento modulatiry - I hope they find a way to allow overriding abstract methods some time in the (near) future!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

I see. Just keep in mind that you will have to re-apply the hack every time you update. This is a major drawback of magento modularity - I hope they find a way to allow overriding abstract methods some time in the (near) future!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpikounis
Member
 
Total Posts:  67
Joined:  2009-01-26
Athens, Greece
 

In a similar situation, when you override a block you need to set the module name in order for translation to work properly. In this case you can do it using the following code (for a block in Mage_Catalog):

protected function _construct() {
        $this
->setAttribute("module_name""Mage_Catalog");
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top