1

I've tried to rewrite a Helper class from a theme we are useing with the following in our modules config.xml

<global>
    <helpers>
        <util>
            <class>Hoi_Util_Helper</class>
        </util>
        <themeoptionsblacknwhite>
            <rewrite>
                <data>Hoi_Util_Helper_ThemeOptionsBlacknwhite_Data</data>
            </rewrite>
        </themeoptionsblacknwhite>
    </helpers>
</global>

I've then created the new helper class which includes our override getProductLabels() function: app/code/local/Hoi/Util/Helper/ThemeOptionsBlacknwhite/Data.php

<?php
class Hoi_Util_Helper_ThemeOptionsBlacknwhite_Data extends Meigee_ThemeOptionsBlacknwhite_Helper_Data
{
    public function getProductLabels ($_product, $type) {
        switch ($type) {
            case 'new':
                if (Mage::getStoreConfig('meigee_blacknwhite_general/productlabels/labelnew')):
                    if (Mage::getStoreConfig('meigee_blacknwhite_general/productlabels/labelnew')):
                        $from = new Zend_Date($_product->getNewsFromDate());
                        $to = new Zend_Date($_product->getNewsToDate());
                        $now = new Zend_Date(Mage::getModel('core/date')->timestamp(time()));
                        if ($from->isEarlier($now) && $to->isLater($now)):
                            return '<span class="label-new">'.$this->__('New').'</span>';
                        else:
                            return false;
                        endif;
                    else:
                        return false;
                    endif;
                else:
                    return false;
                endif;
                break;
            case 'sale':
                if(Mage::getStoreConfig('meigee_blacknwhite_general/productlabels/labelonsale')):
                    exit;
                    $_finalPrice = MAGE::helper('tax')->getPrice($_product, $_product->getFinalPrice());
                    $_regularPrice = MAGE::helper('tax')->getPrice($_product, $_product->getPrice());
                    if ($_regularPrice != $_finalPrice):
                        if (Mage::getStoreConfig('meigee_blacknwhite_general/productlabels/salepercentage')):
                            $getpercentage = number_format($_finalPrice / $_regularPrice * 100, 2);
                            $finalpercentage = 100 - $getpercentage;
                            return '<div class="label-sale percentage">'.number_format($finalpercentage, 0).'% <span>'.$this->__('off').'</span></div>';
                        else:
                            return '<div class="label-sale">'.$this->__('Sale').'</div>';
                        endif;
                    else:
                        return false;
                    endif;
                else:
                    return false;
                endif;
                break;
        }

    }
}

But still Magento is using the origional helper class when it is called with:

<?php echo MAGE::helper('ThemeOptionsBlacknwhite')->getProductLabels($_product, 'sale'); ?>

I have also made sure that our Module is depending on the Meigee_ThemeOptionsBlacknwhite module.

<?xml version="1.0"?>
<config>
    <modules>
        <Hoi_Util>
            <active>true</active>
            <codePool>local</codePool>
            <version>0.1.0</version>
            <depends>
                <Meigee_ThemeOptionsBlacknwhite/>
            </depends>
        </Hoi_Util>
    </modules>
</config>
  • What if you replace themeoptionsblacknwhite with ThemeOptionsBlacknwhite (respecting the case) in your config file ? – Raphael at Digital Pianism May 25 '16 at 11:09
  • @RaphaelatDigitalPianism, That was it! Thank you. I thought that part was meant to be lower case? It seems to be in all the tutorials I've looked through including this one from Inchoo – Holly May 25 '16 at 11:14
  • I posted it as an answer. It's definitely not good practice from the developer of the module you're overriding. – Raphael at Digital Pianism May 25 '16 at 11:20
1

The error is that the original helper is declared case sensitively (which is not a good practice as you have experienced)

So instead of:

    <themeoptionsblacknwhite>
        <rewrite>
            <data>Hoi_Util_Helper_ThemeOptionsBlacknwhite_Data</data>
        </rewrite>
    </themeoptionsblacknwhite>

You should have:

    <ThemeOptionsBlacknwhite>
        <rewrite>
            <data>Hoi_Util_Helper_ThemeOptionsBlacknwhite_Data</data>
        </rewrite>
    </ThemeOptionsBlacknwhite>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.