I am able to set and get config data in a field under General table with the test code. The Magento backend displays the field as the screenshot below shows. The issue is this field is blank, but supposed to display the value from the table. Please help me find what is missing in the field.

enter image description here

system.xml is as follows:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
        <section id="pmm" translate="label" type="text" sortOrder="330" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="currency_conversion" translate="label" type="text" sortOrder="1100" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Currency Conversion</label>
                <field id="usd_to_cad_conversion" translate="label" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
                    <label>USD to CAD Exchange Rate</label> <!-- Custom label -->

my module.xml is as follows:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Perfectmakeupmirrors_CustomShipping" >
            <module name="Magento_Store"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_SalesRule"/>
            <module name="Magento_Backend"/>

Finally, the test code written to set and get the config data is below:

 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.

// Initial code to Bootstrap Magento 2
use Magento\Framework\App\Bootstrap;
use public_html\testcode\Writeconfig;

$bootstrap = Bootstrap::create(BP, $_SERVER); // Magento gets initialized at this point

$objectManager = $bootstrap->getObjectManager();

// Object to get the current store time in PST
$timezone = $objectManager->get('Magento\Framework\Stdlib\DateTime\TimezoneInterface');

$state = $objectManager->get('Magento\Framework\App\State');
// Initial code to Bootstrap Magento 2 ends here

$date = $timezone->date();
// If one needs to diplay date in the formate of Ymd use 'Ymd'
$current_store_time = $date->format('Ymd H:i:s');

echo "<body>";
echo "**********************************************Magento Store Time : " . $current_store_time . "**********************************<br><br>";

// Instantiate class Write_Read_Config.
// Call function to set config data.
// Call function to get config data and display.
$configWriter = $objectManager->get('Magento\Framework\App\Config\Storage\WriterInterface');
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$scopeConfig = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface');

//for all websites
$websites = $storeManager->getWebsites();
$scope = "websites";
$value = 1.26;
foreach($websites as $website) {
    echo $website->getId() . "<br>";
    // Set config data. 
    $configWriter->save("/pmm/currency_conversion/usd_to_cad_conversion", $value, $scope, $website->getId());

// Display Config data.
echo "Current USD to CAD exchange rate is " . $scopeConfig->getValue("/pmm/currency_conversion/usd_to_cad_conversion", "websites");
echo "</body>";
  • This is cache issue
    – Sohel Rana
    Jul 22, 2021 at 0:52
  • The value shows up in the field when in Website and default store view, but not in default config view. Jul 22, 2021 at 5:51
  • Clearing cache doesn't help. Jul 22, 2021 at 5:55
  • You saved in the website scope, so can't see that value in the default scope, which is fine. If you want to see from default scope, then you need to assign in the default scope
    – Sohel Rana
    Jul 22, 2021 at 5:57
  • Yes, I want to see it from default scope. Please specify what change to be done in my code. thanks Jul 22, 2021 at 5:59

1 Answer 1


For default scope:

$configWriter->save("/pmm/currency_conversion/usd_to_cad_conversion", $value, 'default', 0);
  • Thanks, I think should make changes also where I get the value, like $scopeConfig->getValue("pmm/currency_conversion/usd_to_cad_conversion", "default"); Jul 22, 2021 at 7:08
  • No need to do that. $scopeConfig->getValue("pmm/currency_conversion/usd_to_cad_conversion") this will handle rest .
    – Sohel Rana
    Jul 22, 2021 at 8:34
  • Still not working..Not sure why Jul 22, 2021 at 8:37
  • I needed to build to get it fixed. Jul 22, 2021 at 15:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.