Managing Your Extension’s Settings via Magento’s own Settings Page

I had mentioned about this in my previous post that I was about to explain how you can add your custom configuration tab to your module in Magento. You are on your way to find out how to do it! By the way, it’s the third blog post in one month (and second in a day!), I guess I won’t ever have such a spare time in months again so enjoy everybits of it :)

Well the need arised as I had to define simple things yet frequently changing configurations like web service url (bank’s web service url of course!) in my etc/config.xml file. Everytime something had changed I had to go and change the file, create a release and someone else was about to install it. So I had to save it somewhere which I was not needed for that to change!

Of course I would have added this as a simple page to my actual admin page. However that would have looked a “hasty patch”. So we had to add them with the others. I have create a file name system.xml in etc folder file like this:


    
        
            
			service
			text
			1
			1
			1
			10
			
			    
					
					text
					10
					1
					1
					1
					
					    
							
							text
							10
							1
							1
							1
						
						
							
							text
							20
							1
							1
							1
						
					
				
			
        
    

I have defined the fields and where these fields would be seen. Well but I cannot let everyone to see this module right? So I should find a way to integrate my module’s settings page with the magento’s role structure. Open up your config.xml and add these lines:


    
    
        
            
                
                    <title>Allow Everything</title>
                
                
                    
                        
        	            
                               
                                   
                                       
                                            <title>Kartaca Pos Settings</title>
                                            10
                                       
                                   
                                
                            
                        
                    
                
            
        
    
    

Such a long xml code! But it’s better then wasting all your time to find the right php file to edit. And the best part: That’s All Folks! Now you will be able to find your configuration in the Sytem -> Configuration page, under the Services tab. You can change where to add it by changing value of “tab” in system.xml file!

What now? How can I use this? Don’t worry that’s easy too:

//Use this anywhere you want!
//Pos is your module's name but actually it's the one defined in the system.xml file. Rest is about where the variables are in the xml tree
Mage::getStoreConfig("pos/settings/store_id");

I will update github including these codes, but give me some time again :)