Domanda

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.

È stato utile?

Soluzione

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;
    }


}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top