Magento. Ah Magento.

The very name can get responses from web developers ranging from delight to running screaming out of the room. Love it or hate it, it is one of the most used commerce platforms on the planet.

The dev team I work with was having trouble with a custom Magento module. It was designed with a feature switch that would allow for the module to be turned off. This was configured in the xml for the modules etc/system.xml and set in the admin config for the module. The possible values would be Yes or No to turn the module on and off. This would evaluate to true or false (1 or 0) in the module code.

The trouble was that the module was off. And stayed off no matter the setting of the feature switch in the admin. We tried the usual Magento remedies – clear all of the cache, logout/login of the admin, clear cache some more… All to no avail. We checked the Magento exception log, the Magento system log and the system php error log. Nada. No entries.

Next we tried debugging the module by dumping the config setting into a custom log file. The log showed the config value to be null. Aha! A clue!

The code was evaluating if the module was on or off with a conditional test. If the config value was true, its on. If false, then off. The value of null was evaluating to false. But why the null value every time?


You use the┬ácore Mage::getStoreConfig(‘foo’); to get the foo config variable for a module. Foo is replaced by the xml path for the config variable you want to retrieve. However if Magneto cannot find the config variable because it does not exist or you have typed in the wrong path, then it returns a null. No error is logged, no exception thrown and php does not give a warning.

After checking the xml path we found that we had the wrong config variable name. The name we were checking did not exist. Once we had the correct config var name the module feature switch worked like a charm!

The mystery is that Magento does not give a warning in any log if you are asking for a config variable that does not exist.

Ah Magento.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.