I want to save store configuration programtically but I'm just getting one problem after another. Firstly I wanted to use Writer class but since it only updates core_config_data table it doesn't work with more complex models like the one I want to update. Since updating the config by path works via bin/magento config:set I started digging and found out that by using Magento\Config\Model\PreparedValueFactory I should be able to create object with correct backend model name I have to save. Now the problem is that when I create the PreparedValue object it doesn't have the information - the Magento\Config\Model\Config\Structure class that's being instantiated during the create() and is responsible for giving access to system.xml configurations doesn't have any data from said files, it's methods don't return anything.

I'm sure I'm providing correct config path to the Factory so it's not that, it just looks like Structure doesn't have any configurations collected during the run of PreparedValueFactory::create(), can I do something about it or just admit defeat? Or maybe is there an easier method for saving store configs by path from upgrade scripts?

1 Answer 1


I took couple steps back and decided to just run bin/magento config:set command from within the upgrade script and it works as intended.

Do do that you have to call ConfigSetCommand::run() and provide ArrayInput and BufferedOutput as parameters. Of course you can change them to something else that implements needed interfaces but I think that's the easiest way.

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.