Adding a configuration setting

How to add a new defined value to the database

If you are creating a plugin or customizing some code, and you want to create a setting which can be changed in the admin without modifying code, you can put it in the database in an appropriate configuration group. For example, a value relating to shipping should go in configuration group 7 (Shipping and Packaging).

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added) VALUES ('Canada Shipping Surcharge', 'CANADA_SHIPPING_SURCHARGE', '12', 'Additional fee for shipping to Canada - added to quote from shipper', 7, 125, NULL, now());

Global settings should go in configuration group 1 (My Store).

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added) VALUES ('Cut  Charge', 'PER_CUT_CHARGE', '1.25', 'Enter the cut charge', 1, 125, NULL, now());

Distributing configuration changes

If you are adding configuration data as part of a plugin for distribution, you can tell people to run a SQL file with your changes in the installation instructions, or you can do it automatically.

To make configuration changes automatically, add a new function to includes/functions/extra_functions (or the same folder on the admin side), and do the operations there after verifying they haven’t already been done.


if (!defined('SPAM_TEST_TEXT')) {
    $db->Execute(
        "INSERT INTO " . TABLE_CONFIGURATION . " 
            (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function, set_function) 
         VALUES 
            ( 'Hidden input field name.', 'SPAM_TEST_TEXT', 'should_be_273', 'You should change this field name like "sams_cat".', '19', '501', now(), NULL, NULL)"
    );
... 



Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified May 2, 2021 by Scott C Wilson (95a2d20).