Source configuration values fallback mechanism, by highest priority
- environment variables (Magento Cloud)
- core_config_data database table
- config.xml module files
Configuration values fallback mechanism, by highest priority
- Store view
Config values are fully loaded from each sources then merged by priority
Let’s take an example with the number of product per page in a grid mode on category pages. Config path is catalog/frontend/grid_per_page_values
1- environment variables (Magento Cloud)
Theses variables are set via the project web interface.
Pattern name is: env:CONFIG__[STORE]__[XML_PATH]
In our case it will be: env:CONFIG__DEFAULT__CATALOG__FRONTEND__GRID_PER_PAGE_VALUES
Or in .magento.app.yaml
2- env.php & config.php files
Driven by Magento\Framework\App\Config\InitialConfigSource
Values can be generated with app:config:dump system cli or manually added in files
These configuration values will be locked, you wont be able to edit them from admin panel.
If you want to update a value in these files, you’ll have to:
- edit the file
- or remove it from the file to unlock it
3- core_config_data table
Driven by Magento\Config\App\Config\Source\RuntimeConfigSource
If config value was not found in previous step, then a look is made inside core_config_data table.
Config values are populated in this table when saving config form (driven by system.xml files) from admin panel in Stores > Configuration sections.
4- config.xml files
Driven by Magento\Config\App\Config\Source\ModularConfigSource
Finally if config was not found in core_config_data neither, configuration value is loaded from config.xml module file.
Good to know
Config importer pool
There is a config importer pool: Magento\Deploy\Model\DeploymentConfig\ImporterPool
There are 3 importers by default:
At the end of setup:upgrade process, app:config:import will be executed.
The ChangeDetector will compare config values from env.php & config.php with those of the database.
If there are differences then the configurations that need to be updated from the files will be imported into the flag table in the system_config_snapshot row. A new hash will then be generated based on these new values in the config_hash row.
What is the purpose of values stored in system_config_snapshot row?
These values are not taken into account by Magento when building storefront configurations. They are only used by the ChangeDetector which will simulate a save of configuration values (only if config value has been updated) to run before and after save methods.