0

When I save a config value, it updates the database but does not change the content in the configuration > admin section. When I get the value, its the unchanged one from the admin, not the value in the database.

Updating value with configWriterInterface updates values in the database but does not carry the value to the admin. When trying to call the value later with scopeConfigInterface it returns the value from the admin field, not the database.

What am I doing wrong?

 /**
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
 */

 public function __construct(
    \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
) {
    $this->_configWriter = $configWriter;
  }

  $value = 'newvalue';
  $this->_configWriter->save('carriers/testship/name', $value);

Value in the database: value updating in database

Value in the admin: admin value

If I call the value from scopeconfiginterface, I get the Admin value.

// get the Object Manager
$objectManager = $bootstrap->getObjectManager();
$scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');
$value =  $scopeConfig->getValue('carriers/testship/name',  \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
echo "value: ".$value."\n";
value: oldvalue
willboudle
  • 1,705
  • 1
  • 13
  • 18
  • refer this link :-- http://magehelper.blogspot.com/2015/06/get-system-config-values-in-magento-2.html 2> https://magento.stackexchange.com/questions/78457/how-to-get-value-from-core-config-data-table-in-magento-2 – Mohit Patel Apr 17 '20 at 19:19
  • @MohitPatel, That's what I am doing above. The issue is when I use \Magento\Framework\App\Config\Storage\WriterInterface to update the value, it only updates in the database, not in the admin panel. When I "get" the value, it uses the old, unchanged value from my admin, not the value stored in the db. – willboudle Apr 18 '20 at 02:47

0 Answers0