0

I am trying to add an event observer to run before product page load. I am receiving an error.

Here is my config.xml

<config>
    <frontend>
        <events>
            <catalog_product_load_before>
                <observers>
                    <product_load_handler>
                        <class>hsc_pce/observer</class>
                        <method>productLoadHandler</method>
                    </product_load_handler>
                </observers>
            </catalog_product_load_before>
        </events>
    </frontend>
</config>

Here is my observer function

public function productLoadHandler(Varien_Event_Observer $observer)
{
    echo 'foobar';
    return;
}

I receive the echo and this error

foobar
Fatal error: Call to a member function getRequestedRouteName() on a non-object in app/code/core/Mage/Core/Controller/Varien/Action.php on line 226

The echo demonstrates that the function is being called. Error occurs without echo as well. If I die() before return I do not receive the error, so it's happening afterwards.

The error is in a line that is part of the getFullActionName($delimiter='_') function, which is called by the dispatch($action) function.

I've tried digging deeper, leading me to alter the request object, but it's clear that it's leading nowhere and is not the appropriate solution.

What is causing this error, and how can I prevent it?

Update

Mage::app()->getRequest()->getRequestedRouteName() shows that the requested route name is 'catalog'.

2

I was mistakenly extending my observer. It was causing this issue. I had this.

class HSC_PCE_Model_Observer extends Mage_Core_Controller_Front_Action 

I changed it back to this.

class HSC_PCE_Model_Observer
  • 1
    @AmitBera I can't accept my answer for two days. That's how it works. – Goose Apr 27 '16 at 20:24
0

You can get getRequestedRouteName() value from app/code/core/Mage/Core/Controller/Varien/Action.php

Because of it, function of class Mage_Core_Controller_Request_Http.

In order to get getRequestedRouteName() value should try with $action->getRequest()->getRequestedRouteName()

At all place of web section at magento,you can try:

Mage::app()->getRequest()->getRequestedRouteName()
  • I don't understand what solution if any you are offering here. Mage::app()->getRequest()->getRequestedRouteName() does show that the requested route name is 'catalog'. Knowing this doesn't directly prevent the error. How can I get the Varien Action Controller to understand this? I will update my question with this information, thanks. – Goose Apr 27 '16 at 19:30
  • can u please tell me why getRequestedRouteName value need? – Amit Bera Apr 27 '16 at 19:38
  • My module is not running with getRequestedRouteName(). It is being run in the core. I am not touching the core. – Goose Apr 27 '16 at 19:42

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.