I'm trying to fire an observer when a product is added to the shopping cart, here is my code:
app/etc/modules/Mydons_Eventdemo.xml
<?xml version="1.0"?>
<config>
<modules>
<Mydons_Eventdemo>
<active>true</active>
<codePool>local</codePool>
</Mydons_Eventdemo>
</modules>
</config>
app/code/local/Mydons/Eventdemo/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mydons_Eventdemo>
<version>0.1.0</version>
</Mydons_Eventdemo>
</modules>
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<Mydons_Eventdemo_Model_Observer>
<type>singleton</type>
<class>Mydons_Eventdemo_Model_Observer</class>
<method>Mytestmethod</method>
</Mydons_Eventdemo_Model_Observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
</config>
and app/code/local/Mydons/Eventdemo/Model/Observer.php
<?php
class Mydons_Eventdemo_Model_Observer {
public function __construct()
{
echo 'hello world';
die();
}
public function Mytestmethod($observer) {
$event = $observer->getEvent(); //Fetches the current event
$product = $event->getProduct();
$eventmsg = "Current Event Triggered : <I>" . $event->getName() . "</I><br/> Currently Added Product : <I> " . $product->getName()."</I>";
//Adds Custom message to shopping cart
echo Mage::getSingleton('checkout/session')->addSuccess($eventmsg);
//Your Custom Logic Here
//you can use print_r($product) here to get more details
}
}
But when I add a product to the shopping cart, it just ran like it usually does. Is there anything wrong here? Please help!
Update: I checked the log file: system.log and got these:
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 22: parser error : Premature end of data in tag config line 21 in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: ^ in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 22: parser error : Premature end of data in tag config line 2 in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
2014-05-27T07:17:19+00:00 ERR (3): Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: ^ in D:\Webserver\htdocs\magento\includes\src\__default.php on line 22352
But I have no idea what it is.
Update2: I run it again and get a more clearly log message:
2014-05-27T07:29:00+00:00 ERR (3): Warning: include(D:\Webserver\htdocs\magento\includes\src\Mydons_Eventdemo_Model_Observer.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in D:\Webserver\htdocs\magento\includes\src\Varien_Autoload.php on line 93
2014-05-27T07:29:00+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'D:\Webserver\htdocs\magento\includes\src\Mydons_Eventdemo_Model_Observer.php' for inclusion (include_path='D:\Webserver\htdocs\magento\includes\src;.;D:\Webserver\php\PEAR') in D:\Webserver\htdocs\magento\includes\src\Varien_Autoload.php on line 93
app/code/Mydons/Eventdemo/etc/config.xmlis incorrect it should beapp/code/local/Mydons/Eventdemo/etc/config.xml- Zefiryn