Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a helper class in Magento

I'm trying to create a custom helper module in Magento but I'm getting the following error when I call it from a page :

Warning: include(Mage/SEO/Helper/Data.php) [function.include]: failed to open stream: No such file or directory  in /home/strailco/1stclassholidays.com/html/lib/Varien/Autoload.php on line 93

From the template i am using the following to call the helper module:

<?php echo Mage::helper('SEO')->getFullProductUrl($product); ?>

The helper module is set up under:

/app/code/local/SEO/Fullurl/Helper/Data.php
/app/code/local/SEO/Fullurl/etc/config.xml

Data.php calls the function:

<?php 

class getFullProductUrl {

public function getFullProductUrl( $product )
{
}

I have my config.xml set up like this:

<?xml version="1.0"?>
<config>
     <global>
        <helpers>
        <SEO>
        <class>getFullProductUrl</class>
        </SEO>
        </helpers>
   </global>
</config>

I think the problem is the way I have the config.xml set up but I'm struggling to work out the correct way of doing this.

I would be very greatful of any help that you could give. I've been working on this for a couple of days but can't get it working.

Many Thanks

Jason

like image 663
Jason Millward Avatar asked Feb 19 '12 08:02

Jason Millward


People also ask

How do I call helper from Object Manager?

Besides, you can use the below code to use ObjectManager to instantiate the Helper Factory. $object_manager = \Magento\Core\Model\ObjectManager::getInstance(); $helper_factory = $object_manager->get('\Magento\Core\Model\Factory\Helper'); $helper = $helper_factory->get('\Magento\Core\Helper\Data');


2 Answers

Your first problem is the config.xml. You have to tell Magento which class you're using.

...Other Stuff...
<global>
  ...Other Stuff...
  <helpers>
    <SEO>
      <class>SEO_Fullurl_Helper</class>
    </SEO>
   </helpers>
   ...Other Stuff...
</global>
...Other Stuff...

Then you need a Helper in app/code/local/SEO/Fullurl/Helper/Data.php that looks like this:

class SEO_Fullurl_Helper_Data extends Mage_Core_Helper_Abstract
{

    function getFullProductUrl( $product )
    {
    }
}

Then you can do echo Mage::helper('SEO')->getFullProductUrl($product);

like image 75
Max Avatar answered Oct 06 '22 08:10

Max


I had missed the step of adding the module to app/etc/modules/SEO_Fullurl.xml

<?xml version="1.0"?>
<config>
    <modules>
        <SEO_Fullurl>
            <active>true</active>
            <codePool>local</codePool>
        </SEO_Fullurl>
    </modules>
</config>

I hope this helps someone, very easy mistake to make.

like image 24
nickspiel Avatar answered Oct 06 '22 08:10

nickspiel