How to Programmatically Set Magento 2 Core Config Data

How to Programmatically Set Magento 2 Core Config Data

Ever had to programmatically set Magento 2 core config data? Not only that but afterward, retrieve that new value?

I had to! And, today, I’ll share the method to set core config data programmatically in Magento 2.

I have also added how I managed the enabled cache.

The following interface can be used to achieve that

/vendor/magento/framework/App/Config/Storage/WriterInterface.php

using the following save method

public function save($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

Additionally, to delete a core config data value you can use the delete method

public function delete($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

Execute the below code for the solution:

Mehod to programmatically set Magento 2 Core Config Data:

That’s it.

Feel free to share the post and use the Comments section below to discuss any doubts on the topic with me. I’d be happy to help.

Thanks.

 

4.6
(based on 11 Reviews)

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.