Every Magento installation has certain core configuration data already set. When you update those values from the administration interfaces, changes are saved mainly to core_config_data database table.

As always, there are times you need to get your hands on it. In some cases you will wish to chance settings directly from the code. This blog will demonstrates it in the proper way.

Let’s say we want to change “demo store notice” (on/off) – change value from 0 to 1 and vice versa.

Here it is, you can call it wherever in your code:

/*
*turns notice on
*/
Mage::getConfig()->saveConfig('design/head/demonotice', '1', 'default', 0);
/*
*turns notice off
*/
Mage::getConfig()->saveConfig('design/head/demonotice', '0', 'default', 0);

Code which does the magic:

class Mage_Core_Model_Config
{
	.
	.
 
    /**
     * Save config value to DB
     *
     * @param string $path
     * @param string $value
     * @param string $scope
     * @param int $scopeId
     * @return Mage_Core_Store_Config
     */
    public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
    {
        $resource = $this->getResourceModel();
        $resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId);
 
        return $this;
    }
 
	.
	.
}

Give your feedback regarding the post.

If you feel, there is something missing in this blog and you know what can complete it, feel free and submit it in the comment section.

There are currently no comments.