Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Magento store config data programmatically?

To get store config data, I would use this code:

$data = Mage::getStoreConfig('my/path/whatever'); 

Now, how could I save to that node? I tried Alans suggestions from Override Magento Config, but it did not work for me.

Thanks!

like image 339
user4095519 Avatar asked Jan 21 '15 09:01

user4095519


People also ask

How to configure Magento store?

Magento has provided us with a variety of configuration options for our store. Not only it is easy to access but also user-friendly, you just need to go to the admin menu, select Stores > Settings > Configuration.

How to save admin settings in Magento 2?

Magento saves all admin settings in core_config_data table in your Magento database. There you can get values by its path, a string which indicates the path to and a variable name. In order to set data for this table, we can use save () function which is located in \Magento\Framework\App\Config\Storage\WriteInterface.

Can $scopeid be 0 in Magento 2?

$scopeId can be 0 if you set as default or you can find your scope_id in Magento store, store_group, store_website table in database. We have learned how to set configuration data, but what if we want to retrieve config data to use?

How do I set the default scope of a Magento site?

Set the base URL for the default scope: Set the base URL for the base website: Set the base URL for the test store view: If you use the --lock-env option as follows, the command saves the configuration value in <Magento base dir>/app/etc/env.php and disables the field for editing this value in Admin.


2 Answers

Try following:

$value = "100";
Mage::getModel('core/config')->saveConfig('my/path/whatever', $value);

OR

$resource = $this->getResourceModel();
$resource->saveConfig(rtrim('my/path/whatever', '/'), 1, 'default', 0);
like image 199
Emipro Technologies Pvt. Ltd. Avatar answered Oct 20 '22 00:10

Emipro Technologies Pvt. Ltd.


Empire Solution is right but do remember to clean cache after it. So use something like

$value = "100";
Mage::getModel('core/config')->saveConfig('my/path/whatever', $value);
Mage::getModel('core/config')->cleanCache();
like image 27
zainengineer Avatar answered Oct 20 '22 00:10

zainengineer