Magento 1.7 – Class Not Found Error While Extending Core Helper

helpermagento-1.7overrides

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.

Best Answer

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>
Related Topic