Magento 2: Programmatically Add a Value to `core_config_data`Magento2 : How to save system config...

Has any human ever had the choice to leave Earth permanently?

Publishing research using outdated methods

Play Zip, Zap, Zop

How would an AI self awareness kill switch work?

What would the chemical name be for C13H8Cl3NO

What are "industrial chops"?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Do theoretical physics suggest that gravity is the exchange of gravitons or deformation/bending of spacetime?

What are the exceptions to Natural Selection?

Is there a weight limit to Feather Fall?

How to prevent cleaning lady from hunging my lock screen in ubuntu 16.04

How to read 火日参拾月参

Increment each digit in a number to form a new number

Is it possible to grant users sftp access without shell access? If yes, how is it implemented?

Should I reinstall Linux when changing the laptop's CPU?

How did Ancient Greek 'πυρ' become English 'fire?'

Can I write a book of my D&D game?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

How old is the day of 24 equal hours?

Why is it that Bernie Sanders is always called a "socialist"?

Why exactly do action photographers need high fps burst cameras?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

Early credit roll before the end of the film

Gear reduction on large turbofans



Magento 2: Programmatically Add a Value to `core_config_data`


Magento2 : How to save system config programmaticallySetting website config to blank, Magento uses defaultmagento keeps redirecting to my production website and not my staging websiteConfiguration->General Settings keep getting cleared. In core_config_data table path 'genera' value 0 keeps appearingMagento 2: How to Read From Configuration TreeMagento 2 CRUD Models: Create and Update TimeMagento 2 Retrieved core_config_data value is nullinject config programmaticallyRollback magento 2.2.4 givers delimitor errorMagento 2.2.3 - Can't get the URL of logo from core_config_dataMagento 2 Saving store configuration programatically in upgrade script













24















Does Magento 2 have a high level abstraction that allows end-user-programmers to update configuration values in the core_config_data table? Or is using straight SQL the only way to do this in Magento 2?



i.e. in Magento 1, you could do something like this



$config_model = new Mage_Core_Model_Config();
$config_model->saveConfig('my/config/path', $unique_id, 'default', 0);


and save configuration values into core_config_data. Is there an equivalent in Magento 2?










share|improve this question



























    24















    Does Magento 2 have a high level abstraction that allows end-user-programmers to update configuration values in the core_config_data table? Or is using straight SQL the only way to do this in Magento 2?



    i.e. in Magento 1, you could do something like this



    $config_model = new Mage_Core_Model_Config();
    $config_model->saveConfig('my/config/path', $unique_id, 'default', 0);


    and save configuration values into core_config_data. Is there an equivalent in Magento 2?










    share|improve this question

























      24












      24








      24


      8






      Does Magento 2 have a high level abstraction that allows end-user-programmers to update configuration values in the core_config_data table? Or is using straight SQL the only way to do this in Magento 2?



      i.e. in Magento 1, you could do something like this



      $config_model = new Mage_Core_Model_Config();
      $config_model->saveConfig('my/config/path', $unique_id, 'default', 0);


      and save configuration values into core_config_data. Is there an equivalent in Magento 2?










      share|improve this question














      Does Magento 2 have a high level abstraction that allows end-user-programmers to update configuration values in the core_config_data table? Or is using straight SQL the only way to do this in Magento 2?



      i.e. in Magento 1, you could do something like this



      $config_model = new Mage_Core_Model_Config();
      $config_model->saveConfig('my/config/path', $unique_id, 'default', 0);


      and save configuration values into core_config_data. Is there an equivalent in Magento 2?







      php magento2 configuration core-config-data






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 7 '15 at 23:37









      Alan StormAlan Storm

      28.9k19118305




      28.9k19118305






















          5 Answers
          5






          active

          oldest

          votes


















          20














          There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61



          A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64






          share|improve this answer


























          • +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

            – Alan Storm
            Dec 8 '15 at 0:25



















          17














          I wouldn't use a model or a resource model, but MagentoFrameworkAppConfigStorageWriterInterface or MagentoFrameworkAppConfigConfigResourceConfigInterface (the first delegating to the second).



          Pretty straight-forward, too:



          use MagentoFrameworkAppConfigStorageWriterInterface;

          class SomeClass {

          public function __construct(WriterInterface $configWriter)
          {
          $configWriter->save('some/config/path', 'some value');
          }
          }





          share|improve this answer
























          • Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

            – Andrei
            Sep 26 '17 at 16:29



















          4














          You can also use MagentoConfigModelConfig::save. Below a simple sample:



          $configData = [
          'section' => 'MY_SECTION',
          'website' => null,
          'store' => null,
          'groups' => [
          'MY_GROUP' => [
          'fields' => [
          'MY_FIELD' => [
          'value' => $myValue,
          ],
          ],
          ],
          ],
          ];

          // $this->configFactory --> MagentoConfigModelConfigFactory
          /** @var MagentoConfigModelConfig $configModel */
          $configModel = $this->configFactory->create(['data' => $configData]);
          $configModel->save();


          This syntax is not "simple", but it's more safe for some case.
          Du to the save logic, the action might be slower than direct access to the db.



          In my case, $value need to be encrypted. In system.xml, I set the backend model for the field, and the save logic encrypt the data.



          Edit: MagentoConfigModelConfig::setDataByPath more simple to use






          share|improve this answer

































            2














            For a high level abstraction I'd inject MagentoFrameworkAppConfigStorageWriterInterface into the constructor of a data setup script:



            use MagentoFrameworkAppConfigStorageWriterInterface; 

            public function __construct(WriterInterface $configWriter) {...}


            Then use the save() method, for example:



            $website = $this->websiteRepository->get('main_website'); // inject MagentoStoreModelWebsiteRepository;

            $this->configWriter->save('general/country/default', 'US', ScopeInterface::SCOPE_WEBSITES, $website->getId()); // inject MagentoStoreModelScopeInterface;


            Notes:
            Use the plural form of scopes: websites / stores in MagentoStoreModelScopeInterface






            share|improve this answer































              0














              Here a complete sample to handle Magento 2 configuration programatically.



              In my case, i add to clear cache too, else changes does not appear in Store > Config.



              /**
              * @var MagentoConfigModelResourceModelConfig
              */
              protected $resourceConfig;

              /**
              * @var MagentoFrameworkAppCacheTypeListInterface
              */
              protected $cacheTypeList;

              public function __construct(
              MagentoConfigModelResourceModelConfig $resourceConfig,
              MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
              ) {
              $this->resourceConfig = $resourceConfig;
              $this->cacheTypeList = $cacheTypeList;
              }

              public function process()
              {
              $this->resourceConfig->saveConfig(
              'my/config/path',
              $unique_id,
              MagentoFrameworkAppScopeInterface::SCOPE_DEFAULT,
              0
              );
              $this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
              }





              share|improve this answer























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "479"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f92917%2fmagento-2-programmatically-add-a-value-to-core-config-data%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                20














                There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61



                A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64






                share|improve this answer


























                • +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                  – Alan Storm
                  Dec 8 '15 at 0:25
















                20














                There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61



                A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64






                share|improve this answer


























                • +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                  – Alan Storm
                  Dec 8 '15 at 0:25














                20












                20








                20







                There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61



                A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64






                share|improve this answer















                There is the same saveConfig method: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Config/Model/ResourceModel/Config.php#L26-L61



                A usage example from the core: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Payment/Observer/UpdateOrderStatusForPaymentMethodsObserver.php#L59-L64







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 9 '15 at 13:41









                7ochem

                5,77293768




                5,77293768










                answered Dec 8 '15 at 0:06









                Mage2.PROMage2.PRO

                3,61211319




                3,61211319













                • +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                  – Alan Storm
                  Dec 8 '15 at 0:25



















                • +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                  – Alan Storm
                  Dec 8 '15 at 0:25

















                +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                – Alan Storm
                Dec 8 '15 at 0:25





                +1 Useful, thank you! I'm going to leave the question open for a while to see if an @api marked answers bubble up to the top.

                – Alan Storm
                Dec 8 '15 at 0:25













                17














                I wouldn't use a model or a resource model, but MagentoFrameworkAppConfigStorageWriterInterface or MagentoFrameworkAppConfigConfigResourceConfigInterface (the first delegating to the second).



                Pretty straight-forward, too:



                use MagentoFrameworkAppConfigStorageWriterInterface;

                class SomeClass {

                public function __construct(WriterInterface $configWriter)
                {
                $configWriter->save('some/config/path', 'some value');
                }
                }





                share|improve this answer
























                • Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                  – Andrei
                  Sep 26 '17 at 16:29
















                17














                I wouldn't use a model or a resource model, but MagentoFrameworkAppConfigStorageWriterInterface or MagentoFrameworkAppConfigConfigResourceConfigInterface (the first delegating to the second).



                Pretty straight-forward, too:



                use MagentoFrameworkAppConfigStorageWriterInterface;

                class SomeClass {

                public function __construct(WriterInterface $configWriter)
                {
                $configWriter->save('some/config/path', 'some value');
                }
                }





                share|improve this answer
























                • Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                  – Andrei
                  Sep 26 '17 at 16:29














                17












                17








                17







                I wouldn't use a model or a resource model, but MagentoFrameworkAppConfigStorageWriterInterface or MagentoFrameworkAppConfigConfigResourceConfigInterface (the first delegating to the second).



                Pretty straight-forward, too:



                use MagentoFrameworkAppConfigStorageWriterInterface;

                class SomeClass {

                public function __construct(WriterInterface $configWriter)
                {
                $configWriter->save('some/config/path', 'some value');
                }
                }





                share|improve this answer













                I wouldn't use a model or a resource model, but MagentoFrameworkAppConfigStorageWriterInterface or MagentoFrameworkAppConfigConfigResourceConfigInterface (the first delegating to the second).



                Pretty straight-forward, too:



                use MagentoFrameworkAppConfigStorageWriterInterface;

                class SomeClass {

                public function __construct(WriterInterface $configWriter)
                {
                $configWriter->save('some/config/path', 'some value');
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 9 '16 at 9:40









                nevvermindnevvermind

                1,2951118




                1,2951118













                • Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                  – Andrei
                  Sep 26 '17 at 16:29



















                • Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                  – Andrei
                  Sep 26 '17 at 16:29

















                Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                – Andrei
                Sep 26 '17 at 16:29





                Thanks! I think this is the better approach/high level abstraction we should be using. Because MagentoFrameworkAppConfigStorageWriterInterface is implemented by MagentoFrameworkAppConfigStorageWriter which in turn uses MagentoConfigModelResourceModelConfig.

                – Andrei
                Sep 26 '17 at 16:29











                4














                You can also use MagentoConfigModelConfig::save. Below a simple sample:



                $configData = [
                'section' => 'MY_SECTION',
                'website' => null,
                'store' => null,
                'groups' => [
                'MY_GROUP' => [
                'fields' => [
                'MY_FIELD' => [
                'value' => $myValue,
                ],
                ],
                ],
                ],
                ];

                // $this->configFactory --> MagentoConfigModelConfigFactory
                /** @var MagentoConfigModelConfig $configModel */
                $configModel = $this->configFactory->create(['data' => $configData]);
                $configModel->save();


                This syntax is not "simple", but it's more safe for some case.
                Du to the save logic, the action might be slower than direct access to the db.



                In my case, $value need to be encrypted. In system.xml, I set the backend model for the field, and the save logic encrypt the data.



                Edit: MagentoConfigModelConfig::setDataByPath more simple to use






                share|improve this answer






























                  4














                  You can also use MagentoConfigModelConfig::save. Below a simple sample:



                  $configData = [
                  'section' => 'MY_SECTION',
                  'website' => null,
                  'store' => null,
                  'groups' => [
                  'MY_GROUP' => [
                  'fields' => [
                  'MY_FIELD' => [
                  'value' => $myValue,
                  ],
                  ],
                  ],
                  ],
                  ];

                  // $this->configFactory --> MagentoConfigModelConfigFactory
                  /** @var MagentoConfigModelConfig $configModel */
                  $configModel = $this->configFactory->create(['data' => $configData]);
                  $configModel->save();


                  This syntax is not "simple", but it's more safe for some case.
                  Du to the save logic, the action might be slower than direct access to the db.



                  In my case, $value need to be encrypted. In system.xml, I set the backend model for the field, and the save logic encrypt the data.



                  Edit: MagentoConfigModelConfig::setDataByPath more simple to use






                  share|improve this answer




























                    4












                    4








                    4







                    You can also use MagentoConfigModelConfig::save. Below a simple sample:



                    $configData = [
                    'section' => 'MY_SECTION',
                    'website' => null,
                    'store' => null,
                    'groups' => [
                    'MY_GROUP' => [
                    'fields' => [
                    'MY_FIELD' => [
                    'value' => $myValue,
                    ],
                    ],
                    ],
                    ],
                    ];

                    // $this->configFactory --> MagentoConfigModelConfigFactory
                    /** @var MagentoConfigModelConfig $configModel */
                    $configModel = $this->configFactory->create(['data' => $configData]);
                    $configModel->save();


                    This syntax is not "simple", but it's more safe for some case.
                    Du to the save logic, the action might be slower than direct access to the db.



                    In my case, $value need to be encrypted. In system.xml, I set the backend model for the field, and the save logic encrypt the data.



                    Edit: MagentoConfigModelConfig::setDataByPath more simple to use






                    share|improve this answer















                    You can also use MagentoConfigModelConfig::save. Below a simple sample:



                    $configData = [
                    'section' => 'MY_SECTION',
                    'website' => null,
                    'store' => null,
                    'groups' => [
                    'MY_GROUP' => [
                    'fields' => [
                    'MY_FIELD' => [
                    'value' => $myValue,
                    ],
                    ],
                    ],
                    ],
                    ];

                    // $this->configFactory --> MagentoConfigModelConfigFactory
                    /** @var MagentoConfigModelConfig $configModel */
                    $configModel = $this->configFactory->create(['data' => $configData]);
                    $configModel->save();


                    This syntax is not "simple", but it's more safe for some case.
                    Du to the save logic, the action might be slower than direct access to the db.



                    In my case, $value need to be encrypted. In system.xml, I set the backend model for the field, and the save logic encrypt the data.



                    Edit: MagentoConfigModelConfig::setDataByPath more simple to use







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 30 '16 at 10:42

























                    answered Jan 30 '16 at 10:33









                    BriceBrice

                    45836




                    45836























                        2














                        For a high level abstraction I'd inject MagentoFrameworkAppConfigStorageWriterInterface into the constructor of a data setup script:



                        use MagentoFrameworkAppConfigStorageWriterInterface; 

                        public function __construct(WriterInterface $configWriter) {...}


                        Then use the save() method, for example:



                        $website = $this->websiteRepository->get('main_website'); // inject MagentoStoreModelWebsiteRepository;

                        $this->configWriter->save('general/country/default', 'US', ScopeInterface::SCOPE_WEBSITES, $website->getId()); // inject MagentoStoreModelScopeInterface;


                        Notes:
                        Use the plural form of scopes: websites / stores in MagentoStoreModelScopeInterface






                        share|improve this answer




























                          2














                          For a high level abstraction I'd inject MagentoFrameworkAppConfigStorageWriterInterface into the constructor of a data setup script:



                          use MagentoFrameworkAppConfigStorageWriterInterface; 

                          public function __construct(WriterInterface $configWriter) {...}


                          Then use the save() method, for example:



                          $website = $this->websiteRepository->get('main_website'); // inject MagentoStoreModelWebsiteRepository;

                          $this->configWriter->save('general/country/default', 'US', ScopeInterface::SCOPE_WEBSITES, $website->getId()); // inject MagentoStoreModelScopeInterface;


                          Notes:
                          Use the plural form of scopes: websites / stores in MagentoStoreModelScopeInterface






                          share|improve this answer


























                            2












                            2








                            2







                            For a high level abstraction I'd inject MagentoFrameworkAppConfigStorageWriterInterface into the constructor of a data setup script:



                            use MagentoFrameworkAppConfigStorageWriterInterface; 

                            public function __construct(WriterInterface $configWriter) {...}


                            Then use the save() method, for example:



                            $website = $this->websiteRepository->get('main_website'); // inject MagentoStoreModelWebsiteRepository;

                            $this->configWriter->save('general/country/default', 'US', ScopeInterface::SCOPE_WEBSITES, $website->getId()); // inject MagentoStoreModelScopeInterface;


                            Notes:
                            Use the plural form of scopes: websites / stores in MagentoStoreModelScopeInterface






                            share|improve this answer













                            For a high level abstraction I'd inject MagentoFrameworkAppConfigStorageWriterInterface into the constructor of a data setup script:



                            use MagentoFrameworkAppConfigStorageWriterInterface; 

                            public function __construct(WriterInterface $configWriter) {...}


                            Then use the save() method, for example:



                            $website = $this->websiteRepository->get('main_website'); // inject MagentoStoreModelWebsiteRepository;

                            $this->configWriter->save('general/country/default', 'US', ScopeInterface::SCOPE_WEBSITES, $website->getId()); // inject MagentoStoreModelScopeInterface;


                            Notes:
                            Use the plural form of scopes: websites / stores in MagentoStoreModelScopeInterface







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 13 '18 at 0:37









                            William TranWilliam Tran

                            380511




                            380511























                                0














                                Here a complete sample to handle Magento 2 configuration programatically.



                                In my case, i add to clear cache too, else changes does not appear in Store > Config.



                                /**
                                * @var MagentoConfigModelResourceModelConfig
                                */
                                protected $resourceConfig;

                                /**
                                * @var MagentoFrameworkAppCacheTypeListInterface
                                */
                                protected $cacheTypeList;

                                public function __construct(
                                MagentoConfigModelResourceModelConfig $resourceConfig,
                                MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
                                ) {
                                $this->resourceConfig = $resourceConfig;
                                $this->cacheTypeList = $cacheTypeList;
                                }

                                public function process()
                                {
                                $this->resourceConfig->saveConfig(
                                'my/config/path',
                                $unique_id,
                                MagentoFrameworkAppScopeInterface::SCOPE_DEFAULT,
                                0
                                );
                                $this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
                                }





                                share|improve this answer




























                                  0














                                  Here a complete sample to handle Magento 2 configuration programatically.



                                  In my case, i add to clear cache too, else changes does not appear in Store > Config.



                                  /**
                                  * @var MagentoConfigModelResourceModelConfig
                                  */
                                  protected $resourceConfig;

                                  /**
                                  * @var MagentoFrameworkAppCacheTypeListInterface
                                  */
                                  protected $cacheTypeList;

                                  public function __construct(
                                  MagentoConfigModelResourceModelConfig $resourceConfig,
                                  MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
                                  ) {
                                  $this->resourceConfig = $resourceConfig;
                                  $this->cacheTypeList = $cacheTypeList;
                                  }

                                  public function process()
                                  {
                                  $this->resourceConfig->saveConfig(
                                  'my/config/path',
                                  $unique_id,
                                  MagentoFrameworkAppScopeInterface::SCOPE_DEFAULT,
                                  0
                                  );
                                  $this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
                                  }





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    Here a complete sample to handle Magento 2 configuration programatically.



                                    In my case, i add to clear cache too, else changes does not appear in Store > Config.



                                    /**
                                    * @var MagentoConfigModelResourceModelConfig
                                    */
                                    protected $resourceConfig;

                                    /**
                                    * @var MagentoFrameworkAppCacheTypeListInterface
                                    */
                                    protected $cacheTypeList;

                                    public function __construct(
                                    MagentoConfigModelResourceModelConfig $resourceConfig,
                                    MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
                                    ) {
                                    $this->resourceConfig = $resourceConfig;
                                    $this->cacheTypeList = $cacheTypeList;
                                    }

                                    public function process()
                                    {
                                    $this->resourceConfig->saveConfig(
                                    'my/config/path',
                                    $unique_id,
                                    MagentoFrameworkAppScopeInterface::SCOPE_DEFAULT,
                                    0
                                    );
                                    $this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
                                    }





                                    share|improve this answer













                                    Here a complete sample to handle Magento 2 configuration programatically.



                                    In my case, i add to clear cache too, else changes does not appear in Store > Config.



                                    /**
                                    * @var MagentoConfigModelResourceModelConfig
                                    */
                                    protected $resourceConfig;

                                    /**
                                    * @var MagentoFrameworkAppCacheTypeListInterface
                                    */
                                    protected $cacheTypeList;

                                    public function __construct(
                                    MagentoConfigModelResourceModelConfig $resourceConfig,
                                    MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
                                    ) {
                                    $this->resourceConfig = $resourceConfig;
                                    $this->cacheTypeList = $cacheTypeList;
                                    }

                                    public function process()
                                    {
                                    $this->resourceConfig->saveConfig(
                                    'my/config/path',
                                    $unique_id,
                                    MagentoFrameworkAppScopeInterface::SCOPE_DEFAULT,
                                    0
                                    );
                                    $this->cacheTypeList->cleanType(MagentoFrameworkAppCacheTypeConfig::TYPE_IDENTIFIER);
                                    }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 12 mins ago









                                    Antoine MartinAntoine Martin

                                    867




                                    867






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Magento Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f92917%2fmagento-2-programmatically-add-a-value-to-core-config-data%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        迭戈·戈丁...

                                        A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

                                        1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...