Magento2 Admin – How to Get Config Values from Specific Store View

magento2

Currently, I'm getting my values like:

$this->_scopeConfig->getValue('settings/basics/language', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

But this, of course, gets me the default value.

How do I get the config value of a certain store view?

Best Answer

When you look into Magento\Framework\App\Config\ScopeConfigInterface in getValue() method

This method accept the 3 parameter

  • $path The path through the tree of configuration values e.g., 'general/store_information/name'
  • string $scopeType The scope to use to determine config value, e.g., 'store' or 'default'
  • null|string $scopeCode

So If you want to get store config by store wise then you just need to pass second (so you can define you want value as storewise or website) as well as third parameter (you can pass your store code here).

use Magento\Framework\App\Config\ScopeConfigInterface;

protected $scopeConfig;


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

Now you can get store config value by

$this->scopeConfig->getValue('your/path/config',\Magento\Store\Model\ScopeInterface::SCOPE_STORE,'store_code');
Related Topic