
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.
<?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:
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.
Click one of our contacts below to chat on WhatsApp