In Magento 1 it was possible to set/retrieve config values by website or store i.e

by website:


or via store


However in magento 2 the config is set via the

Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig


My question now is, how can I retrieve the values by website/store?

  • have you checked my answer? Jul 20, 2018 at 11:36

4 Answers 4


Here's how I do it in my helper:


namespace VendorName\ModuleName\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\ScopeInterface;

class Data extends AbstractHelper
    const MODULE_ENABLE = 'sectionName/groupName/fieldName';

     * @var ScopeConfigInterface
    protected $scopeConfig;

    public function __construct(ScopeConfigInterface $scopeConfig)
        $this->scopeConfig = $scopeConfig;

     * Get store config value
     * @return string
    public function getConfigValue($field, $storeId = null)
        return $this->scopeConfig->getValue(

     * Check is enable
     * @return string
    public function isEnable($storeId = null)
        return $this->getConfigValue(self::MODULE_ENABLE, $storeId);

You can change the SCOPE_STORE to following:

const SCOPE_STORES   = 'stores';
const SCOPE_GROUPS   = 'groups';
const SCOPE_WEBSITES = 'websites';
const SCOPE_GROUP   = 'group';
const SCOPE_WEBSITE = 'website';

Just Use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, In your constructor argument and set the class property: $this->scopeConfig = $scopeConfig;

Now to Get the configuration value for Store or Website View use:

Store View:

$this->scopeConfig->getValue('settings/reference/prefix', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

Website View:

$this->scopeConfig->getValue('settings/reference/prefix', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE);
$this->_scopeConfig->getValue('settings/reference/prefix', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE); //Get value by Website

$this->_scopeConfig->getValue('settings/reference/prefix', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); //Get value by store

In template (phtml) files, I use in the following way:

$config = $block->getLayout()->createBlock(\Magento\Config\Block\System\Config\Form::class);
$configValue = $config->getConfigValue('web/secure/base_url'); // website, store will be detected automatically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.