Save core config data in Magento using install script

Save core config data in Magento

Our development team is always keen to update everything in the database using Magento install or upgrade scripts. Whether it is creating or updating table or inserting / updating / deleting records from the existing tables. Anything you want to do in the database it is always good practice to do it using install or upgrade scripts so that if you have different environments then you don’t need to manually change the settings in admin interface. In our case we have 5 different environments (Development/ Function Testing / User Acceptance Testing /Release Candidate and Production) so we always find it useful to have everything related to database to be in install or update scripts including data values so that moving code from one environment to another becomes hassle free. Today we are going to talk about how you can save core config data values directly from the Magento install or upgrade scripts using the following code snippet

$installer = $this; $installer->startSetup(); $setup = new Mage_Core_Model_Config(); $setup->saveConfig('google/analytics/active', '0', 'default', 0); $installer->endSetup();

In the above example, this will save data (‘0’) directly into core_config table for where path is ‘google/analytics/active’ and scope is ‘default’ and scope id is 0.

For reference you can have a look at parameters of saveConfig function below -:

public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
{ .....

Hope this article helped you in some way. Please leave us your comment and let us know what do you think about this article? Thanks.[/sourcecode]