0

We can get system configuration values using

Mage::getStoreConfig($xmlPath);

But how can we set such configuration field programatically? I would expect some method like

Mage::setStoreConfig($xmlPath, $val);

But the closest thing I'm seeing is

Mage::app()
    ->getStore()
    ->setConfig($xmlPath, $val);
    ->save();

But this is not updating the config value. Thanks for your time and help.

3

This should work

/*
*turns notice on
*/
Mage::getConfig()->saveConfig('design/head/demonotice', '1', 'default', 0);
/*
*turns notice off
*/
Mage::getConfig()->saveConfig('design/head/demonotice', '0', 'default', 0);
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;
    }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.