I’m looking to learn more about the internals of Magento!
I recently used Inchoo’s tutorial to allow administrators to set a crontab schedule from System > Configuration. See it here. In it, I noticed that a setting which is usually set in
config.xml is being set in the database table
<crontab> <jobs> <my_custom_crontab> <schedule><cron_expr>* * * * *</cron_expr></schedule> <run><model>mymodule/observer::hookMethod</model></run> </my_custom_crontab> </jobs> </crontab>
Alternate Database Record:
scope scope_id path value default 0 crontab/jobs/my_custom_crontab/schedule/cron_expr * * * * *
Can anyone tell me
- What config settings can be located in the database, or if all of them can be.
- Where Magento’s logic (code) to pull these values from the database lives.
- What the hierarchy looks like / what is given priority.
One side effect I’ve noticed from storing these
config.xml settings in the database is that they suddenly have scope. (default, website, store, store view.) I’m not aware of replicating such scope in the
config.xml files, so I’m also wondering how that figures in.
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
In theory you can set any config value in the database (table
But for most of the cases, the values saved there have the
path column like this:
section/group/field. So only 3 parts. The cron schedule is an exception.
The general config of Magento comes from different sources. All of these sources are merged into one big xml. In case there are 2 nodes with the same xpath, every source will overwrite the previous source.
Here is the order of loading the config.
- All the xml files located in
app/etc(no subfolders). This is loaded in
- All the modules. Files located in
app/etc/modules. This is done by
config.xmlfor all active modules loaded previously. Done in
core_config_datatable values. Done in
From all of these, magento creates one big config xml and smaller ones for each website and store view deriving from the main one.
And here is an example.
Let’s say that you have this inside the
config.xml of a module.
<default> <!-- config scope node --> <some_section> <some_group> <some_field>2</some_field> </some_group> </some_section> </default>
And you have in the db a line with the same path
some_section/some_group/some_field and with the scope
default, but the value is
In the big config the final value will be
1 because the db config is loaded last.
A side note. When reading a value from the config, you cannot know if the value comes from any xml file or from the db and you shouldn’t care.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0