How To Get Data From System Configuration In Magento 2
Are you a beginner in Magento 2 development? If so, I guess you are on your first tutorial on Magento 2 module development!
And hence, the below solution to get data from system configuration in Magento 2 is going to be used often. You might as well bookmark this post!
For example, you want to get the data of Magento 2 extension status, if it is enabled or disabled.
Magento 2 allows creating custom configuration fields and get config data programmatically from other modules or core Magento!
Method To Get Data From System Configuration In Magento 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; protected $scopeConfig; public function __construct( ScopeConfigInterface $scopeConfig ) { $this->scopeConfig = $scopeConfig; } public function getConfigValue() { return $this->scopeConfig->getValue("sectionId/groupId/fieldId",ScopeInterface::SCOPE_STORE); } |
A simple solution, but still, the Comments section is always open for the readers to post their doubts on the topic. I’m here to help with your doubts.
Do share the post with the Magento community via social media.
Thanks.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
Meet Meetanshi — A Leading E-Commerce Developer on Clutch!
Programmatically Create Configurable Product in Magento 2 Simplified
Next