Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from Magento System Configuration

Tags:

php

magento

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?

like image 900
Jorge Avatar asked May 05 '11 03:05

Jorge


People also ask

How can I get configuration data in Magento 2?

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').

How can you fetch a system configuration value programmatically?

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.

Where is system xml in Magento?

The system. xml file is located under etc/adminhtml/system. xml in a given Magento 2 extension.


1 Answers

$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); 
like image 130
Mukesh Chapagain Avatar answered Oct 16 '22 10:10

Mukesh Chapagain