0

I am trying to extend the core helper class But found the below error..
Fatal error: Class 'Mage_Kishore_Kp_Helper_Data' not found

Below are the path of my files..
1. app/etc/modules/Kishore_Kp.xml
2. app/code/community/Kishore/Kp/etc/config.xml
3. app/code/community/Kishore/Kp/Helper/Data.php

These are my files..

1.Kishore_Kp.xml

<?xml version="1.0"?>
<config>
<modules>
    <Kishore_Kp>
        <active>true</active>
        <codePool>community</codePool>
        <depends>
            <Mage_Core/>
            <Mage_Catalog/>
        </depends>
    </Kishore_Kp>
</modules>
</config>  

2. config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Kishore_Kp>
        <version>1.0.0</version>
    </Kishore_Kp>
</modules>

<global>        
    <helpers>
        <kishore_kp>
            <class>Kishore_Kp_Helper</class>
        </kishore_kp>
    </helpers>
</global>

<frontend>
    <routers>
        <kishore_kp>
            <use>standard</use>
            <args>
                <module>Kishore_Kp</module>
                <frontName>kpswitcher</frontName>
            </args>
        </kishore_kp>
    </routers>
</frontend>
</config>  

3.Data.php

<?php

class Kishore_Kp_Helper_Data extends Mage_Core_Helper_Abstract
{
const FULL_SITE_COOKIE = 'USE_FULL_SITE';

public function getMobileToDesktopUrl() {
echo "helllllo";exit;
}

}    

I am calling this helper in the footer.phtml as..

    <a href="<?php echo Mage::helper('kishore_kp')->getMobileToDesktopUrl() ?>">View</a>

can any one says what am I doing wrong ?
These are the only files related to the module.I have given all the files here.
So can any one find some error in this code, please inform..
Thanks.

1

Follow bellow steps:

Step : 1 Create config.xml file at location

app\code\local\AR\Themeswitcher\etc\config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <AR_Themeswitcher>
            <version>1.0.0</version>
        </AR_Themeswitcher>
    </modules>
    <global>
        <blocks>
            <themeswitcher>
                <class>AR_Themeswitcher_Block</class>
            </themeswitcher>
        </blocks>
        <models>
            <themeswitcher>
                <class>AR_Themeswitcher_Model</class>
            </themeswitcher>
            <core>
                <rewrite>
                    <design_package>AR_Themeswitcher_Model_Core_Design_Package</design_package>
                </rewrite>
            </core>
        </models>
        <helpers>
            <themeswitcher>
                <class>AR_Themeswitcher_Helper</class>
            </themeswitcher>
        </helpers>
    </global>
    <frontend>
        <routers>
            <themeswitcher>
                <use>standard</use>
                <args>
                    <module>AR_Themeswitcher</module>
                    <frontName>themeswitcher</frontName>
                </args>
            </themeswitcher>
        </routers>
    </frontend>
</config>

Step : 2 Create Data.php file at location

app\code\local\AR\Themeswitcher\Helper\Data.php

<?php
class AR_Themeswitcher_Helper_Data extends Mage_Core_Helper_Abstract
{
    const FULL_SITE_COOKIE = 'USE_FULL_SITE';

    public function getMobileToDesktopUrl() {
        return Mage::getUrl('themeswitcher/switch/desktop');
    }

    public function getDesktopToMobileUrl() {
        return Mage::getUrl('themeswitcher/switch/mobile');
    }
}

?>

Step : 3 Create SwitchController.php file at location

app\code\local\AR\Themeswitcher\controllers\SwitchController.php

<?php
class AR_Themeswitcher_SwitchController extends Mage_Core_Controller_Front_Action
{
    /**
     * Switch to Desktop theme
     */
    public function desktopAction()
    {
        setcookie(AR_Themeswitcher_Helper_Data::FULL_SITE_COOKIE, 1, 0, '/');
        $this->_redirectReferer();
    }

    /**
     * Switch to Mobile theme
     */
    public function mobileAction()
    {
        setcookie(AR_Themeswitcher_Helper_Data::FULL_SITE_COOKIE, 0, 0, '/');
        $this->_redirectReferer();
    }
}
?>

Step : 4 Create Package.php file at location

app\code\local\AR\Themeswitcher\Model\Core\Design\Package.php

<?php
class AR_Themeswitcher_Model_Core_Design_Package extends Mage_Core_Model_Design_Package
{
    /**
     * Get regex rules from config and check user-agent against them. We override to
     * determine if the design exception should be ignored based on presence of a cookie.
     * 
     * @param string $regexpsConfigPath
     * @return mixed
     * @see Mage_Core_Model_Design_Package
     */
    protected function _checkUserAgentAgainstRegexps($regexpsConfigPath)
    {
        $ignoreException = null;
        if (isset($_COOKIE[AR_Themeswitcher_Helper_Data::FULL_SITE_COOKIE])) {
            $ignoreException = $_COOKIE[AR_Themeswitcher_Helper_Data::FULL_SITE_COOKIE];
        }
        return $ignoreException ? false : parent::_checkUserAgentAgainstRegexps($regexpsConfigPath);
    }
}

Step : 5 Create AR_Themeswitcher.xml file at location

app\etc\modules\AR_Themeswitcher.xml

<?xml version="1.0"?>
<config>
    <modules>
        <AR_Themeswitcher>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Core/>
            </depends>
        </AR_Themeswitcher>
    </modules>
</config>

Step : 6 Called helper in the footer.phtml

<a href="<?php echo $this->helper('themeswitcher')->getMobileToDesktopUrl() ?>">View</a>
  • it is not working still that class not found error is coming.. – Kishore Patra Jan 13 '16 at 6:58
  • have you create Data.php file at location app\code\community\Kishore\Kp\Helper? – Abdul Jan 13 '16 at 7:19
  • yes I have created. And the code I have mentioned. – Kishore Patra Jan 13 '16 at 7:24
  • But I use same code my end it is working fine – Abdul Jan 13 '16 at 7:34
  • Pls go admin side System -> Cache Management and refresh all caches after check frontend. – Abdul Jan 13 '16 at 7:36
0

What are you trying to do ? Overriding class or extending it ? Because your code show that you are trying to extend it.
If this is the case your error mean that you are calling a class that does not exist.
To solve this here are the common steps :
- clean your Magento cache because Magento is caching config files (including config.xml files)
- call the helper with the key kishore_kp : Mage::helper('kishore_hp')->getMobileToDesktopUrl();


I don't know if this is a copy/paste error but the ending node of your config.xml file is missing </config>
In Magento overriding class mean that when Magento try to call the class A it try to load the overriding class B instead. It is like everywhere Magento is calling class A you replace the code with class B. To make it more dynamic an override have to be declared in config.xml with the node <rewrite> (http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/)
In your case you just extending class A meaning that when class A is called your class B have no effect but when class B is called you herite all functions of class A

  • I tried using 'kishore_kp : Mage::helper('kishore_hp')->getMobileToDesktopUrl();'..No result.. I have edited a little bit. plz see the updated one. – Kishore Patra Jan 13 '16 at 4:36
  • All seems good to me. Did you clear all your caches ? Block cache / FPC / APC / etc ? – Matthéo Geoffray Jan 13 '16 at 9:00
  • Yes. I have clear and disabled the caches. – Kishore Patra Jan 13 '16 at 9:03
  • If you go in your backend in System > Configuration > Advanced > Advanced, did you see your module in the list ? – Matthéo Geoffray Jan 13 '16 at 9:40
  • Yes . there is present "Kishore_Kp" and it is enabled. – Kishore Patra Jan 13 '16 at 9:43

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.