Reading list Switch to dark mode

    System configuration data for different store or website in Magento 2

    Updated 29 February 2024

    In this blog I’ll explain how you can get the system configuration data for different store or website.

    In the below example we are getting system config value for a website and a store. The getValue method of scopeConfig requires only one parameter which is the relevant path of the configuration that you are trying to get. The second parameter is optional which tells that what is the scope type. It is “default” by default but we can pass values like “website“, “store“. The third parameter represents website or store based on the scope type.

    So we want system configuration data for a website then we set the scope type to “website” and pass the website as the third argument.

    $this->scopeConfig->getValue(
            'general/country/default', 
            \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, 
            $website
        );

    So we want system configuration data for a website then we set the scope type to “store” and pass the store as the third argument.

    $this->scopeConfig->getValue(
            'general/country/default', 
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE, 
            $store
        );

    Please let me know in the comments if you have any queries.

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home