Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

How to Get Store Configuration value in Magento 2?

Hello Devs, In this tutorial we are going to see how to get store configuration value or store config value in Magento 2.

How to Get Store Configuration value in Magento 2?
Written by
JKJigar Karangiya
Published
Reading time
1 min read

Jigar Karangiya · · 1 min read

Hello Devs, In this tutorial we are going to see how to get store configuration value or store config value in Magento 2.

Magento stores all the configuration values in the core_config_data table based on a specific scope (opens in new tab) website, store, or view.

We can utilize the Magento\Store\Model\ScopeInterface class in our helper file as below.

Method 1 :

php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace VendorName\ModuleName\Helper;
 
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;
 
class Data extends AbstractHelper
{
    const XML_CONFIG_PATH = 'config/to/path'; /* in the format of {sections/group/field}  */
 
    public function getConfig()
    {
        /**
         * for website specific value
         */
        $configValue = $this->scopeConfig->getValue(self::XML_CONFIG_PATH,ScopeInterface::SCOPE_STORE);
 
        /**
         * for website specific value
         * 
         * $configValue = $this->scopeConfig->getValue(self::XML_CONFIG_PATH,ScopeInterface::SCOPE_WEBSITE);
         */
 
 
        /**
         * for group specific value
         * 
         * $configValue = $this->scopeConfig->getValue(self::XML_CONFIG_PATH,ScopeInterface::SCOPE_GROUP);
         */
        return $configValue;
    }
}

Now, you can inject the helper class anywhere and use the getConfig() function to get the config value.

Method 2 :

You can also manually specify the Store ID in the getConfig() param and get store-specific configuration values like below.

php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace VendorName\ModuleName\Helper;
 
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
 
class Data extends AbstractHelper
{
    const XML_AMAZON_PAYMENT_ACTIVE = 'payment/amazon_payment/active';
 
    /**
     * @var ScopeConfigInterface
     */
    protected $scopeConfig;
 
    /*
     * @return string
     */
    public function getConfig($path, $storeId = null)
    {
        return $this->scopeConfig->getValue(
            $path,
            ScopeInterface::SCOPE_STORE,
            $storeId
        );
    }
 
    /*
     * @return bool
     */
    public function isActive()
    {
        return $this->getConfig(self::XML_AMAZON_PAYMENT_ACTIVE, 1); // Pass store id in the second parameter
    }
}

Method 3 :

We can also get configuration values using Object Manager like below.

php
<?php
$value = \Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Magento\Framework\App\Config\ScopeConfigInterface::class)
    ->getValue(
        'sections/group/field',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
    );

Using the above code, you can easily get store config value by scope in Magento 2.

You may also like :

How to get value from env.php in Magento 2?

How to create a root script in Magento 2?

That’s it for this tutorial, See you in the next blog. Thank you!!

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe