Question

I followed this tutorial, from this site: http://coding.smashingmagazine.com/2012/03/01/basics-creating-magento-module/ I have to mentioned that I have the same code as in the site. The problem is when I create/update o product I got in var/log/system.log this error:

"2013-12-02T08:36:36+00:00 ERR (3): Warning: include(C:\xampp\htdocs\mage\magento\includes\src\Mage_Smashingmagazine_Logproductupdate_Model_Observer.php): failed to open stream: No such file or directory  in C:\xampp\htdocs\mage\magento\includes\src\Varien_Autoload.php on line 93
2013-12-02T08:36:36+00:00 ERR (3): Warning: include(): Failed opening 'C:\xampp\htdocs\mage\magento\includes\src\Mage_Smashingmagazine_Logproductupdate_Model_Observer.php' for inclusion (include_path='C:\xampp\htdocs\mage\magento\includes\src;.;C:\xampp\php\pear\;D:\xampp\php\zend1\library')  in C:\xampp\htdocs\mage\magento\includes\src\Varien_Autoload.php on line 93"

Can anyone tell me why??? The compilation is disabled and I clear the chache frequently. Thx in advance /*******************************************/

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <SmashingMagazine_LogProductUpdate>
            <version>0.0.1</version>
        </SmashingMagazine_LogProductUpdate>
    </modules>
    <global>
        <events>
            <catalog_product_save_after>
                <observers>
                    <smashingmagazine_logproductupdate>
                          <class>smashingmagazine_logproductupdate/observer</class>
                          <method>logUpdate</method>
                        <type>singleton</type>
                    </smashingmagazine_logproductupdate >
                </observers>
            </catalog_product_save_after>
        </events>
    </global>
</config>

/**********************************************/

This is the observer

<?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 SmashingMagazine_LogProductUpdate_Model_Observer extends Varien_Event_Observer
{
    /**
     * Magento passes a Varien_Event_Observer object as
     * the first parameter of dispatched events.
     */
    public function logUpdate(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();
        Mage::log(
            "{$name} ({$sku}) updated",
            null, 
            'product-updates.log',
            true
        );
    }
}
Was it helpful?

Solution

Some point need to take care while creating config xml in Magento.

  1. Always use <Namesapce_Modulename> not <NameSpace_ModuleName> as it will not work when you create object using 'namesapce/modulename' as Magento try to find the class like Namespace_Modulename_Model_Class not NameSpace_ModuleName_Model_Class.

  2. In your case either change your Namespace and Moduel name properly or use the below config.xml

    <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Smashingmagazine_Logproductupdate> <version>0.0.1</version> </Smashingmagazine_Logproductupdate> </modules> <global> <events> <catalog_product_save_after> <observers> <smashingmagazine_logproductupdate> <class>smashingmagazine_logproductupdate/observer</class> <method>logUpdate</method> <type>singleton</type> </smashingmagazine_logproductupdate > </observers> </catalog_product_save_after> </events> </global> </config>

  3. and change the folder name accordingly.

OTHER TIPS

Add this in your config.xml inside the <global> tag

<models>
    <smashingmagazine_logproductupdate>
        <class>SmashingMagazine_LogProductUpdate_Model</class>
    </smashingmagazine_logproductupdate>
</models>

and clear the cache

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top