Page 1 of 1

Hooks + Admin Configuration [how to?]

Posted: Wed Apr 15, 2026 9:24 am
by PiLLaO
Hi,

How it's the correct way to add SQL configuration in a Hook to make it configurable via admin?

I'm looking for a easy way to install a hook without run sql via phpmyadmin.

I think it's more easy to new PhoenixCart users.

Thanks in advance.

Re: Hooks + Admin Configuration [how to?]

Posted: Wed Apr 15, 2026 9:25 am
by burt
Example needed of what you are trying to achieve...

Re: Hooks + Admin Configuration [how to?]

Posted: Wed Apr 15, 2026 9:44 am
by PiLLaO
For example:

To save images on separate folders, that can be configured the folder on admin instead of the file.

By default a hook don't need to install anything to work, but I think that this way bring more configurable options to a hook

Re: Hooks + Admin Configuration [how to?]

Posted: Thu Apr 16, 2026 10:01 am
by PiLLaO
If I do it as a module, what type of module would it be? The only thing I can think of is header_tags.

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 7:57 am
by PiLLaO
Nobody can bring me a little help? I'm not asking for code, only for the way to proceed...

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 8:20 am
by burt
If you need configuration options, you defeat the purpose of a Hook (which is meant to be fairly simple).
So, if your baseline is "no SQL", then you must make a Module.

Try Something. If it doesn't work, try something else.
Welcome to the world of code dev. What should take 1 hour often ends up taking 1 day.

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 8:38 am
by Omar_one
try this out

Code: Select all

<?php


class hook_admin_siteWide_MyCustomHook {
    public function listen_injectSiteEnd() {
        // 1. Check if the config exists; if not, install it.
        $this->checkConfig();

        // 2. Only run logic if enabled in Admin
        if (MODULE_MY_CUSTOM_HOOK_STATUS  === 'True') {
            return '';
        }
    }

private function checkConfig() {
    // Check if the constant is defined
    if (!defined('MODULE_MY_CUSTOM_HOOK_STATUS')) {
        $GLOBALS['db']->query("
            INSERT INTO configuration 
            (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) 
            VALUES 
            ('Enable Custom Hook', 'MODULE_MY_CUSTOM_HOOK_STATUS', 'True', 'Do you want to enable this hook?', '1', '100', 'tep_cfg_select_option(array(\'True\', \'False\'),', now())
        ");
    }
}
}

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 9:11 am
by raiwa
I often use a module for my addons which just holds configuration settings and install/uninstall sql queries.
For example: Wholesale lite store module:
app.php/addons/free_addon/wholesale_lite

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 9:15 am
by PiLLaO
burt wrote: Mon Apr 20, 2026 8:20 am If you need configuration options, you defeat the purpose of a Hook (which is meant to be fairly simple).
So, if your baseline is "no SQL", then you must make a Module.

Try Something. If it doesn't work, try something else.
Welcome to the world of code dev. What should take 1 hour often ends up taking 1 day.
I'm not a code dev, but I know how it works in may case try and error many times, I'm "here" since many years, but now the core code it's very different and I want to create something that don't touch core and easy to share. I only ask for show the new way.

The cuestion was, if I need to make it as a module, what kind of module need to use, because not payment, shipping, content...
Omar_one wrote: Mon Apr 20, 2026 8:38 am try this out

Code: Select all

<?php


class hook_admin_siteWide_MyCustomHook {
    public function listen_injectSiteEnd() {
        // 1. Check if the config exists; if not, install it.
        $this->checkConfig();

        // 2. Only run logic if enabled in Admin
        if (MODULE_MY_CUSTOM_HOOK_STATUS  === 'True') {
            return '';
        }
    }

private function checkConfig() {
    // Check if the constant is defined
    if (!defined('MODULE_MY_CUSTOM_HOOK_STATUS')) {
        $GLOBALS['db']->query("
            INSERT INTO configuration 
            (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) 
            VALUES 
            ('Enable Custom Hook', 'MODULE_MY_CUSTOM_HOOK_STATUS', 'True', 'Do you want to enable this hook?', '1', '100', 'tep_cfg_select_option(array(\'True\', \'False\'),', now())
        ");
    }
}
}
Thanks you so much, you give me more than I asking for, thanks

Re: Hooks + Admin Configuration [how to?]

Posted: Mon Apr 20, 2026 9:16 am
by PiLLaO
raiwa wrote: Mon Apr 20, 2026 9:11 am I often use a module for my addons which just holds configuration settings and install/uninstall sql queries.
For example: Wholesale lite store module:
app.php/addons/free_addon/wholesale_lite
Thanks rainer, I'll take a look later