Reputation: 13
I have a list of custom options in magento config and I need to change them programmatically when an user clicks on "Save Config". In generally it's not a big problem to get it done using observer but I need to have one option like "Pack of options" and if user choose one of package appropriate options must be changed programatically. It's not a big deal too:
Mage::getConfig()->saveConfig('path/to/config/', 1, 'default', 0);
Mage::getConfig()->saveConfig('path/to/config2/', 1, 'default', 0);
But the problem is that I can't get it working for different stores, it's working for default scope only. Example:
Mage::getConfig()->saveConfig('path/to/config2/', 1, 'german', 0);
isn't working.
How can I update options programatically for certain stores only? So the user could check witch store he wants to apply options too?
Thanks for any help.
Upvotes: 1
Views: 3319
Reputation: 498
Look at the definition of the function :
public function saveConfig($path, $value, $scope = 'default', $scopeId = 0)
The scope can actually take only 3 values : 'default', 'stores' or 'websites'. Let's suppose your german store has 3 as Id, here is the code that would work :
$config = Mage::getModel('core/config');
$config->saveConfig('path/to/config/', 'value_to_set', 'stores', 3);
For a website-scoped config :
$config->saveConfig('path/to/config/', 'value_to_set', 'websites', $websiteId);
Upvotes: 2
Reputation: 15216
Try this:
$storeCode = 'german';
$store = Mage::getModel('core/store')->load($storeCode);
$path = 'path/to/config';
$config = Mage::getModel('core/config_data');
$config->setValue('Your value here');
$config->setPath($path);
$config->setScope('stores');
$config->setScopeId($store->getId());
$config->save();
Upvotes: 3