{"id":257,"date":"2018-12-07T12:37:49","date_gmt":"2018-12-07T12:37:49","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/12\/07\/get-store-config-value-by-scope-in-magento-2\/"},"modified":"2025-03-18T05:42:19","modified_gmt":"2025-03-18T05:42:19","slug":"get-store-config-value-by-scope-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-store-config-value-by-scope-in-magento-2\/","title":{"rendered":"How to Get Store Config Value by Scope in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Scope in Magento 2 allows setting the configuration based on a specific website, store or view. A bigger business leads to having multiple stores, websites and store views. Sometimes, it\u2019s required to get values from the various scope and use it somewhere while creating an extension. This requires to&nbsp;<strong><em>get store config value by scope in Magento 2<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All the adminhtml settings are saved in&nbsp;<strong>core_config<\/strong>&nbsp;table of your Magento 2 database.&nbsp;You just need to call&nbsp;<strong>getConfig()<\/strong>&nbsp;method and add a second param with the scope to get the stored value for website, store or the store view.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to get store config value by scope in Magento 2:<br><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Helper\n \nuse Magento\\Store\\Model\\ScopeInterface;\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\n \nclass Data extends AbstractHelper{\n    public function getConfig($scope)\n    {\n        try {\n            switch($scope){\n                case 'store':\n                    return $this->scopeConfig->getValue('config\/to\/path', ScopeInterface::SCOPE_STORE);        \/\/ From store view\n                case 'website':\n                    return $this->scopeConfig->getValue('config\/to\/path', ScopeInterface::SCOPE_WEBSITE);    \/\/ From Website\n                default:\n                    return $this->scopeConfig->getValue('config\/to\/path', ScopeInterface::SCOPE_STORE);\n            }\n \n        } catch (\\Exception $e) {\n            return false;\n        }\n    }\n}\n?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using the above code, you can easily get store config value by scope in Magento 2. Remove the code with the scope as per your requirement. Do comment your doubts, suggestions, feedback, and queries. I would really appreciate your inputs and help you as soon as possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to hit the 5 stars below to reward my write-ups.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scope in Magento 2 allows setting the configuration based on a specific website, store or view. A bigger business leads to having multiple stores, websites&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":10211,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/257\/revisions\/10211"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}