I just wandering on how I can get the configuration data for my custom module. The configuration can be set from the admin system->configuration
and how to pull it in frontend?
In Magento 2, configuration data is stored to core_config_data database table. The easiest way to get a configuration value from there, is using the following code snippet. It's the most closest alternative to construction, which we had used in Magento 1: Mage::getStoreConfig('section/group/field').
To Fetch the System Store Configuration Values by Scope level, Store or Website, You need to use ScopeConfigInterface with getValue() method. First Argument sectionId/groupId/fieldId is from your etc/adminhtml/system. xml file. The second Argument will be the Scope Value.
The system. xml file is located under etc/adminhtml/system. xml in a given Magento 2 extension.
$configValue = Mage::getStoreConfig('sectionName/groupName/fieldName');
sectionName, groupName and fieldName are present in etc/system.xml file of your module.
The above code will automatically fetch config value of currently viewed store.
If you want to fetch config value of any other store than the currently viewed store then you can specify store ID as the second parameter to the getStoreConfig
function as below:
$store = Mage::app()->getStore(); // store info $configValue = Mage::getStoreConfig('sectionName/groupName/fieldName', $store);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With