This is the first observer I'm writing. I'm testing the observer with the controller_action_predispatch
that should fire when I load a page as an example. This is the files I created:
/app/etc/modules/EPS_CustomizationURL.xml
<?xml version="1.0"?>
<config>
<modules>
<EPS_CustomizationURL>
<codePool>local</codePool>
<active>true</active>
</EPS_CustomizationURL>
</modules>
</config>
/app/code/local/EPS/CustomizationURL/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<EPS_CustomizationURL>
<version>0.0.1</version>
</EPS_CustomizationURL>
</modules>
<global>
<models>
<epscustomizationurl>
<class>EPS_CustomizationURL_Model</class>
</epscustomizationurl>
</models>
</global>
<adminhtml>
<events>
<!-- observe the event -->
<controller_action_predispatch>
<observers>
<epscustomizationurl>
<class>epscustomizationurl/observer</class>
<method>epsURLCreator</method>
</epscustomizationurl>
</observers>
</controller_action_predispatch>
</events>
</adminhtml>
</config>
/app/code/local/EPS/CustomizationURL/Model/Observer.php
<?php
class EPS_CustomizationURL_Model_Observer {
public function epsURLCreator($observer) {
$this->_redirectUrl("http://www.google.com");
}
}
?>
So, as far as I understand as soon as my page loads or even before it I should be redirected to http://www.google.com. This is the only way I could think of to know if my observer is firing.
What am I missing? Any wrong naming, wrong event or _redirectUrl
is not working? I'm on Magento 1.9.
EDIT: All the caches are disabled so the cache should not be the problem:
I also tried just logging something instead of redirect and changing the event to customer_login
:
<?xml version="1.0"?>
<config>
<modules>
<EPS_CustomizationURL>
<version>0.0.1</version>
</EPS_CustomizationURL>
</modules>
<global>
<models>
<epscustomizationurl>
<class>EPS_CustomizationURL_Model</class>
</epscustomizationurl>
</models>
<events>
<!-- observe the event -->
<customer_login>
<observers>
<eps_customizationurl_model_observer>
<type>model</type>
<class>epscustomizationurl/observer</class>
<method>epsURLCreator</method>
</eps_customizationurl_model_observer>
</observers>
</customer_login>
</events>
</global>
</config>
And my observer:
<?php
class EPS_CustomizationURL_Model_Observer {
public function epsURLCreator($observer) {
Mage::log('I just made an Observer!', null, 'system.log', true);
}
}
But still can't see anything in /var/log/system.log
_redirectUrl
does not exist in your class. Did you clear the cache?var/cache
from your magento instance