{"id":615,"date":"2019-09-26T21:15:20","date_gmt":"2019-09-26T21:15:20","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/26\/trigger-an-event-on-magento-2-save-store-configuration\/"},"modified":"2025-05-22T15:54:44","modified_gmt":"2025-05-22T10:24:44","slug":"trigger-an-event-on-magento-2-save-store-configuration","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/trigger-an-event-on-magento-2-save-store-configuration\/","title":{"rendered":"How to Trigger an Event on Magento 2 Save Store Configuration"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Many times, the default Magento 2 falls short in the functionalities that are essential for an E-commerce store and hence using the events is a must thing to extend the functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 triggers <strong>admin_system_config_changed_section<\/strong> event after the save store config action is performed. You may want to use this event to use to get the value from a third party API and throw an error if unmatched.&nbsp;For example, when using the barcode generator to create barcode labels and print them, the barcode library needs to be installed. Otherwise, it throws the error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, to throw this error, you need to <em><strong>trigger an event on Magento 2 save store configuration<\/strong><\/em> to get the admin configuration value and use the below solution for the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Trigger an Event on Magento 2 Save Store Configuration:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if your <em><strong>system.xml<\/strong><\/em> looks something like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;section id=\"meetanshitab\" translate=\"label\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n    &lt;group id=\"general\" translate=\"label\" type=\"text\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n        &lt;label>General Configuration&lt;\/label>\n        &lt;field id=\"name\" translate=\"label\" type=\"text\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\">\n            &lt;label>Enter Name&lt;\/label>\n        &lt;\/field>\n    &lt;\/group>\n&lt;\/section><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, the <strong>section id<\/strong> is meetanshitab which has to be <strong>added in the event name<\/strong> as shown in the below solution:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong><em>event.xml<\/em><\/strong>&nbsp;file at&nbsp;<strong>app\/code\/Vendor\/Module\/etc\/adminhtml\/events.xml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Event\/etc\/events.xsd\">\n    &lt;event name=\"admin_system_config_changed_section_meetanshitab\">\n        &lt;observer name=\"custom_admin_system_config_changed_section_meetanshitab\" instance=\"Vendor\\Module\\Observer\\ConfigChange\"\/>\n    &lt;\/event>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. create <em><strong>ConfigChange.php<\/strong><\/em> file at <strong>app\/code\/Vendor\/Module\/Observer\/<\/strong> folder<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Module\\Observer;\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\Framework\\Event\\Observer as EventObserver;\nuse Magento\\Framework\\App\\RequestInterface;\nuse Magento\\Framework\\App\\Config\\Storage\\WriterInterface;\nclass ConfigChange implements ObserverInterface\n{\n    private $request;\n    private $configWriter;\n    public function __construct(RequestInterface $request, WriterInterface $configWriter)\n    {\n        $this->request = $request;\n        $this->configWriter = $configWriter;\n    }\n    public function execute(EventObserver $observer)\n    {\n        $meetParams = $this->request->getParam('groups');\n        $name = $meetParams['general']['fields']['name']['value'];\n        \/\/to print thatn value in system.log\n        \\Magento\\Framework\\App\\ObjectManager::getInstance()->get('Psr\\Log\\LoggerInterface')->info($name);\n        return $this;\n    }\n}\n?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Hope it helps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the above solution with fellow developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many times, the default Magento 2 falls short in the functionalities that are essential for an E-commerce store and hence using the events is a&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-615","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"predecessor-version":[{"id":15255,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions\/15255"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}