How to Add Time Control in Admin Configuration Using System.xml File in Magento 2
Businesses have deadlines!
Magento 2 stores are no exceptions.
There are multiple times when you need to add time control in Magento 2 store.
For instance, when you launch offers, you have to set the cut off time for ending the offers. By using time control in admin configuration, you can manage when the offer will end and the prices will set back to normal.
Or, managing the timelines for order delivery and payments can be easy using the timer.
You can use the below solution to add time control in admin configuration using system.xml file in Magento 2. along with your custom code.
Solution to Add Time Control in Admin Configuration using system.xml File in Magento 2
To set as shown above, you need to follow these three steps;
Step 1:
Create registration.php file at app\code\Vendor\Module directory
1 2 3 4 5 |
<?php use \Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_Module', __DIR__); |
Step 2:
Create module.xml file at app\code\Vendor\Module\etc directory
1 2 3 4 5 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Module" setup_version="1.0.0"/> </config> |
Step 3:
Create system.xml file at app\code\Vendor\Module\etc\adminhtml directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <tab id="extension_name" translate="label" class="extension_name" sortOrder="100"> <label></label> </tab> <section id="section_id" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Example</label> <tab>extension_name</tab> <resource>Vendor_Module::module_name</resource> <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>General</label> <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enable</label> <source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model> </field> <field id="cutofftime" translate="cut off time" type="time" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Cut off Time</label> </field> </group> </section> </system> </config> |
Done! You are good to go.
If you have questions related to this post, feel free to ask in the Comments section below.
I would be happy to solve your queries.
Do not forget to share this post with Magento Community via social media.
Thank you.
Related Posts:
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
How to Change Copyright Notice in Magento 2
Experts Opinion to Increase Average Order Value in E-commerce
Next