Reputation: 1389
Log: When I click on add to cart, I get this error log of two lines in system.log :
2015-10-16T00:27:33+00:00 ERR (3): Warning: include(Mage/Modulename/Model/Observer.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/magento2/lib/Varien/Autoload.php on line 94
2015-10-16T00:27:33+00:00 ERR (3): Warning: include(): Failed opening 'Mage/Modulename/Model/Observer.php' for inclusion (include_path='/opt/lampp/htdocs/magento2/app/code/local:/opt/lampp/htdocs/magento2/app/code/community:/opt/lampp/htdocs/magento2/app/code/core:/opt/lampp/htdocs/magento2/lib:.:/opt/lampp/lib/php') in /opt/lampp/htdocs/magento2/lib/Varien/Autoload.php on line 94
Here is my plugin named Namespace_Modulename:
File: /app/code/local/Namespace/Modulename/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Namespace_Modulename>
<version>0.0.1</version>
</Namespace_Modulename>
</modules>
<!-- Configure our module's behavior in the global scope -->
<frontend>
<routers>
<modulename>
<use>standard</use>
<args>
<module>Namespace_Modulename</module>
<frontName>modulename</frontName>
</args>
</modulename>
</routers>
</frontend>
<global>
<models>
<Namespace_Modulename>Namespace_Modulename_Model</Namespace_Modulename>
</models>
<events>
<checkout_cart_product_add_after>
<observers>
<namespace_modulename_checkout_cart_product_add_after_observer>
<type>singleton</type>
<class>modulename/observer</class>
<method>my_custom_method</method>
</namespace_modulename_checkout_cart_product_add_after_observer>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
</config>
File: /app/code/local/Namespace/Modulename/Model/Observer.php
<?php
/**
* Our class name should follow the directory structure of
* our Observer.php model, starting from the namespace,
* replacing directory separators with underscores.
* i.e. app/code/local/SmashingMagazine/
* LogProductUpdate/Model/Observer.php
*/
class Namespace_Modulename_Model_Observer
{
/**
* Magento passes a Varien_Event_Observer object as
* the first parameter of dispatched events.
*/
public function my_custom_method(Varien_Event_Observer $observer)
{
// Retrieve the product being updated from the event observer
$product = $observer->getEvent()->getProduct();
// Write a new line to var/log/product-updates.log
$name = $product->getName();
$sku = $product->getSku();
file_put_contents("/opt/lampp/htdocs/magento2/test","sdddddddss");
Mage::log(
"{$name} ({$sku}) updated",
null,
'product-updates.log'
);
}
}
File: app/etc/modules/Namespace_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Modulename>
<active>true</active>
<codePool>local</codePool>
</Namespace_Modulename>
</modules>
</config>
Upvotes: 2
Views: 3025
Reputation: 1175
Please change the following line in config.xml from
<class>modulename/observer</class>
to
<class>Namespace_Modulename_Model_Observer</class>
Upvotes: 5
Reputation: 3019
The class group (or namespace) of your model isn't correct.
You're calling <class>modulename/observer</class>
in your observer, but modulename
isn't defined as a class group.
<models>
<Namespace_Modulename>Namespace_Modulename_Model</Namespace_Modulename>
</models>
Should become
<models>
<my_unique_class_group>Namespace_Modulename_Model</my_unique_class_group>
</models>
and then you can get your class from the factory using <class>my_unique_class_group/observer</class>
Upvotes: 0