Magento Add default value to System Configuration Option fields


/ Published in: PHP
Save to your folder(s)

This article shows how to add default value to any system configuration option fields. System configuration option fields means those options under System -> Configuration.

Suppose, you have the following system.xml file. System.xml file is necessary to add admin configuration options.


Copy this code and paste it in your HTML
  1. system.xml
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <config>
  4. <sections>
  5. <mysection translate="label" module="mymodule">
  6. <label>My Section</label>
  7. <tab>catalog</tab>
  8. <frontend_type>text</frontend_type>
  9. <sort_order>110</sort_order>
  10. <show_in_default>1</show_in_default>
  11. <show_in_website>1</show_in_website>
  12. <show_in_store>1</show_in_store>
  13. <groups>
  14. <mygroup translate="label" module="mymodule">
  15. <label>My Group</label>
  16. <frontend_type>text</frontend_type>
  17. <sort_order>99</sort_order>
  18. <show_in_default>1</show_in_default>
  19. <show_in_website>1</show_in_website>
  20. <show_in_store>1</show_in_store>
  21. <fields>
  22. <myfield translate="label comment">
  23. <label>My Field</label>
  24. <frontend_type>text</frontend_type>
  25. <sort_order>1</sort_order>
  26. <show_in_default>1</show_in_default>
  27. <show_in_website>1</show_in_website>
  28. <show_in_store>1</show_in_store>
  29. </myfield>
  30. </fields>
  31. </mygroup>
  32. </groups>
  33. </mysection>
  34. </sections>
  35. </config>
  36.  
  37.  
  38. Now, to add default value to the admin configuration options, you need to write the following in config.xml file of your module. The should be inside config node.
  39.  
  40. config.xml
  41. <default>
  42. <mysection>
  43. <mygroup>
  44. <myfield>My Default Value</myfield>
  45. </mygroup>
  46. </mysection>
  47. </default>
  48.  
  49. http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/xml_structure_for_admin_configurations

URL: http://blog.chapagain.com.np/magento-add-default-value-to-system-configuration-option-fields/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.