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?


Here's how i do it in my helper:

namespace Vendor\Module\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\ScopeInterface;

class Data extends AbstractHelper
    protected $storeManager;
    protected $objectManager;

    const XML_PATH_KEY = 'vendor_module/general/key'; 

    public function __construct(Context $context,
        \Magento\Framework\ObjectManagerInterface $objectManager,
        StoreManagerInterface $storeManager
    ) {
        $this->objectManager = $objectManager;
        $this->storeManager  = $storeManager;

    public function getConfigValue($field, $storeId = null)
        return $this->scopeConfig->getValue(
            $field, ScopeInterface::SCOPE_STORE, $storeId

    public function getApiKey($storeId = null)
        return $this->getConfigValue(self::XML_PATH_KEY, $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';
| improve this answer | |

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);
| improve this answer | |
$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
| improve this answer | |

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
| improve this answer | |

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.