Magento Observer does not shoot

I try to start the observer whenever the product is updated in the admin file. To register updates.

Config.xml

<?xml version="1.0"?> <config> <modules> <Mod_Products> <version>1.0.0</version> </Mod_Products> </modules> <models> <Mod_Products> <class>Mod_Products_Model</class> </Mod_Products> </models> <events> <catalog_product_save_after> <observers> <Mod_Products_stock> <type>singleton</type> <class>Mod_Products_Model</class> <method>logUpdate</method> </Mod_Products_stock> </observers> </catalog_product_save_after> </events> </config> 

Observer.php

 class Mod_Products_Model_Observer { public function logUpdate($observer) { $event = $observer->getEvent()->getControllerAction()->getFullActionName(); Mage::log('Event Fired: ' . $event); Mage::log(json_encode($observer->getEvent())); } } 

There are no errors in the log and is not displayed.

+4
source share
7 answers

Skip files one at a time.

applications / etc / modules / Mod_Products.xml

 <?xml version="1.0"?> <config> <modules> <Mod_Products> <!-- Change to Community codePool if in app/code/community --> <codePool>local</codePool> <active>true</active> </Mod_Products> </modules> </config> 

Application / code / local / Mod / Products / etc. /config.xml

 <?xml version="1.0"?> <config> <modules> <Mod_Products> <version>1.0.0</version> </Mod_Products> </modules> <!-- Marking models as global sometimes helps --> <global> <models> <Mod_Products> <class>Mod_Products_Model</class> </Mod_Products> </models> </global> <events> <catalog_product_save_after> <observers> <mod_products_model_observer> <type>singleton</type> <class>Mod_Products_Model_Observer</class> <method>logUpdate</method> </mod_products_model_observer> </observers> </catalog_product_save_after> </events> </config> 

Application / code / local / Mod / Products / Model / Observer.php

 class Mod_Products_Model_Observer { public function logUpdate($observer) { $event = $observer->getEvent()->getControllerAction()->getFullActionName(); Mage::log('Event Fired: ' . $event); Mage::log(json_encode($observer->getEvent())); } } 

Pay attention to the file names and directories and to the different xml descriptors in the updated config.xml file. Let me know if this works for you.

0
source

I don’t know why op accepted Jason’s answer, which actually didn’t solve it, but here is the correct answer for future searchers (I noticed this from Emi's comment on my own answer): missing adminhtml tag!

The config should look like this (if I didn't miss anything):

 <adminhtml> <events> <catalog_product_save_after> <observers> <Mod_Products_stock> <type>singleton</type> <class>Mod_Products_Model</class> <method>logUpdate</method> </Mod_Products_stock> </observers> </catalog_product_save_after> </events> </adminhtml> 

hope this helps.

+2
source

The class inside your configuration should be an Observer class, so change to:

 <class>Mod_Products_Model_Observer</class> 
0
source

A possible solution for those who are faced with this problem is that your Magento application may not have proper write permissions to the app/var folder. Especially if you are working with a UNIX / Linux-based OS.

To solve this problem, just find your terminal at the root of your Magento application. Once you are there, use the following command to give your var folder the correct permissions:

sudo chmod 777 -R var/

As soon as I did this, my application was able to register and create other folders in the folder structure.

0
source

I struggled with the same situation and finally found that Mage_Log was not working. Try using something like die ("I'm here"); instead of Mage :: Log () to track and check if it occurs in your class or not. If so, try enabling Mage_Log through Configuration: Developer: Log Setting (Enabled = Yes). Also check to see if Mage_Log is enabled in Configuration: Advanced.

0
source

As soon as I have the same problem, and I decided that just dropping the system cache, so that you can also try to clear the cache to update its configuration.

0
source

check if your module exists in "disable module output" and System -> configuration -> advenced -> disable module output is enabled.
And check the syslog file

-one
source

Source: https://habr.com/ru/post/1498976/


All Articles