🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How To Set Store Configuration Value In InstallSchema In Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

The post gives the solution to programmatically set store configuration value in InstallSchema in Magento 2.

For example, you are using a Magento 2 extension in your store and want to change the default Magento 2 field values while extension installation. The below code is the solution for the same.

Changing the default field values in Magento 2 while extension installation becomes easy with this method. You can also implement this manually from the admin panel by logging in and navigate to Stores > Configuration.

Method to Set Store Configuration Value In InstallSchema in Magento 2:

Place the below code in app/code/Vendor/Extension/InstallSchema.php:

<?php

namespace Vendor\Extension\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\Store;

class UpgradeSchema implements UpgradeSchemaInterface
{
    protected $resourceConfig;

    public function __construct(
        ConfigInterface $resourceConfig)
    {
        $this->resourceConfig = $resourceConfig;
    }

    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        $this->resourceConfig->saveConfig(
            'checkout/cart/delete_quote_after',
            '3000',
            ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
            Store::DEFAULT_STORE_ID
        );


        $setup->endSetup();
    }
}

That’s it.

Do share the post with fellow Magento developers via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.