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
2
  • refer this link :-- magehelper.blogspot.com/2015/06/… 2> magento.stackexchange.com/questions/78457/… Commented Apr 17, 2020 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
    Commented Apr 18, 2020 at 2:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.