Have you created your own module for Zencart? And you would like to add configuration setting for your module, so that your client can configure your module via Admin area? Here is how to do that…
What I do usually is adding new group (with your module name) under Configuration in zencart administrator, then add fields under that group to be setup. Just like if you go to Configuration > My Store, you will find many settings there. All of this fields are declared inside your database, specifically inside zen_configuration_group and zen_configuration table (NB: zen_ is used as table prefix).
So let’s insert new row to your zen_configuration_group to create new group under “Configuration” menu. The following SQL script will add “My New Module” group under “Configuration” menu and position it in the last order. Use this script as template.
1 2 3 4 5
INSERT INTO configuration_group (configuration_group_id, configuration_group_title, configuration_group_description, sort_order, visible) VALUES (NULL, 'My New Module', 'My New Module Description....', '1', '1'); UPDATE configuration_group SET sort_order = last_insert_id() WHERE configuration_group_id = last_insert_id();
Secondly, to add config items under your new “Configuration > My New Module” use the following SQL
1 2 3 4 5 6 7 8 9
SET @last_id=0; SELECT (@last_id:=configuration_group_id) AS last_id FROM configuration_group WHERE configuration_group_title= 'My New Module'; INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('', 'Small Image Height', 'IMAGE_VIEWER_SMALL_IMAGE_HEIGHT','75','Description of Small Image Height Setting. Default 75.', @last_id, 1, now());
Note that to run this SQL smoothly without bothering with your zencart database table prefix, execute this script from zencart admin area Tools > Install SQL Patches.
Once you executed those SQL, you will find My New Module category under Configuration menu and Small Image Height setting inside that category. You can then access the value of this configuration from your module straight away by using configuration_key which you have set in your SQL (i.e. echo IMAGE_VIEWER_SMALL_IMAGE_HEIGHT). Please leave comment if you find any difficulties or feel grateful with this blog. Cheers.