We used to store configuration to store some value which affects our store and provides functionality from the configuration. All Magento store settings are saved and stored in core_config table in Magento 2.
The below code show how to get store config values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php namespace Dolphin\GetStoreVal\Helper; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Store\Model\ScopeInterface; class Data extends AbstractHelper { protected $scopeConfig; XML_PATH_KEY = 'section_name/group_name/field_name';// add your path here public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) { $this->scopeConfig = $scopeConfig; } public function getConfigValue($field, $storeId = null) { return $this->scopeConfig->getValue($field, ScopeInterface::SCOPE_STORE, $storeId); } public function getFieldVal($storeId = null) { return $this->getConfigValue(self::XML_PATH_KEY, $storeId); } } |
You can change the SCOPE_STORE to following:
1 2 3 4 5 | SCOPE_STORES For Stores SCOPE_GROUPS For Groups SCOPE_WEBSITES For Websites SCOPE_GROUP For Group SCOPE_WEBSITE For Website |
I hope this helps you. For any doubts regarding this topic, please write your doubts in the comments section.