I have searched I don't know how many Google pages before deciding to write this question and I know there is a already some very nice answers from Marius and Alan Storm to very similar questions but I unfortunately haven't been able to demystify why my observer doesn't fire as it should.
It is not the first time I'm playing with observers and I have flushed the cache either from admin and manually the var/cache folder, I have tried different working syntaxes to call the model (complete_model_path_with underscores,module/model,uppercase, lowercase). I have other observers working fine everyday on the same install and I tried to do it the exact same way without success. I have also tried to call with singleton instead of model. I have tried the three scope views (global, frontend and adminhtml). I have searched for any direct or indirect core overwrite, it is still possible that I would have missed one hidden inside an other module but I almost always use modules from well known developpers who respect most of Magento standards.
There is part of my code:
app/code/local/NameSpace/Module/etc/config.xml
<global>
<models>
<module>
<class>NameSpace_Module_Model</class>
<resourceModel>module_mysql4</resourceModel>
</module>
</models>
<events>
<catalog_product_save_before>
<observers>
<module>
<type>singleton</type>
<class>NameSpace_Module_Model_Observer</class>
<method>catalogProductSaveBefore</method>
</module>
</observers>
</catalog_product_save_before>
</events>
</global>
app/code/local/NameSpace/Module/Model/Observer.php
class NameSpace_Module_Model_Observer
{
public function catalogProductSaveBefore(Varien_Event_Observer $observer)
{
$product = $observer->getEvent()->getProduct();
file_put_contents("OBSERVER.TXT","FIRED");
echo "hello";
exit();
return $this;
}
}
app/etc/modules/NameSpace_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<NameSpace_Module>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
<depends>
<Mage_Catalog />
</depends>
</NameSpace_Module>
</modules>
</config>
I even tried to add random caracters in the code to provoque a fatal error but it is never called. It could be a very simple mistake of mine, all I know is that I carefully overlooked my code and I can't seem to find the issue.
Please try to comment before giving an answer as I already tried many solutions and maybe yours already.
Thank you very much in advance for your help, any suggestion will be appreciated!
There is some moments where I am asking myself;
-Am I really a developer?
These moments where all of my complex code is verified and fully functionnal in all possible ways except something so basic and small.
After verifying if my observer model really exists inside of Magento:
require_once('/home/user/public_html/app/Mage.php');
Mage::init();
$observer = Mage::getModel('module/observer');
It does, I also realised that the output was simple text...
Adding
<?php
before any php code is always a good idea!