I am currently trying to add an observer on a Magento Community 1.6.2.0
I am trying to add an observer to checkout_onepage_controller_success_action that checks the ordered products' SKU and performs additional code that creates and emails a Voucher code if the SKU is correct.
I can create and email the codes correctly when testing on another page, but every attempt to set the method as an observer have failed with no explanation.
in app/etc/modules/giftCheck_sales.xml
<?xml version="1.0"?>
<config>
<modules>
<giftCheck_sales>
<active>true</active>
<codePool>local</codePool>
</giftCheck_sales>
</modules>
</config>
in app/code/local/giftCheck/sales/etc
<?xml version="1.0"?>
<config>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<giftCheck_sales>
<type>singleton</type>
<class>giftCheck_sales/observer</class>
<method>exportOrder</method>
</giftCheck_sales>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
</config>
in app/code/local/giftCheck/sales/models/observer.php
class giftCheck_sales_Model_Observer
{
public function exportOrder(Varien_Event_Observer $observer)
{
die('test');
}
}
My issue is no matter what I do, I can never get these observers to work. Regardless of what code I place in my observer it never gets executed.
What is the issue with (I presume my XML) the way I am setting up this observer?
Any help is greatly appreciated!
To view all active modules, go to System->Configuration->Advanced->Advanced
. If a module doesn't appear in that list, then Magento doesn't know your module exists.
As far as your code, I haven't worked with Magento 1.6.2.0 specifically, but I can see some things that might be causing you trouble. First among them is your namespace and module name. These should always begin with an uppercase letter:
app/etc/modules/Giftcheck_Sales.xml
app/code/local/Giftcheck/Sales/
Which means of course that Giftcheck_Sales.xml
should look like this:
<?xml version="1.0"?>
<config>
<modules>
<Giftcheck_Sales>
<active>true</active>
<codePool>local</codePool>
</Giftcheck_Sales>
</modules>
</config>
Another problem I see is you haven't told Magento where to find your models. There are also some problems with casing.
Your config should look something like this:
<?xml version="1.0"?>
<config>
<global>
<models>
<giftcheck_sales>
<class>Giftcheck_Sales_Model</class>
</giftcheck_sales>
</models>
</global>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<giftcheck_sales>
<class>giftcheck_sales/observer</class>
<method>exportOrder</method>
</giftcheck_sales>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
</config>
There also seems to be a problem with your directory structure.
app/code/local/giftCheck/sales/models/observer.php
should be:
app/code/local/Giftcheck/Sales/Model/Observer.php
And the contents of that file should look something like:
class Giftcheck_Sales_Model_Observer
{
public function exportOrder(Varien_Event_Observer $observer)
{
die('test');
}
}
Don't forget to correct the casing of your observer's class name.
Hope this helps.
Here some correction i can give you to add your config.xml may be due to case sensitive issue you are not able to call your observer
in app/code/local/giftCheck/sales/etc
<?xml version="1.0"?>
<config>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<giftcheck_sales>
<type>singleton</type>
<class>giftcheck_sales/observer</class>
<method>exportOrder</method>
</giftcheck_sales>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
</config>
hope this will sure work for you.
you configuration is wrong. your code should be like this,
<config>
<frontend>
<global>
<events>
<checkout_onepage_controller_success_action>
<observers>
<GiftCheck_Sales>
<type>singleton</type>
<class>GiftCheck_Sales_Model_Observer</class>
<method>exportOrder</method>
</GiftCheck_Sales>
</observers>
</checkout_onepage_controller_success_action>
</events>
</global>
</frontend>
</config>
You missed global tag.And your observer class should be like this,
class GiftCheck_Sales_Model_Observer
{
public function exportOrder(Varien_Event_Observer $observer)
{
echo "test";
}
}
Thats it..!!let me know if any problem to use this code..!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.