Hooks + Admin Configuration [how to?]

Talk about Hooks. Share Hooks you have made.
Post Reply
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Hooks + Admin Configuration [how to?]

Post 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.
Last edited by PiLLaO on Wed Apr 15, 2026 9:44 am, edited 1 time in total.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4550
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Hooks + Admin Configuration [how to?]

Post by burt »

Example needed of what you are trying to achieve...
I am not here to build for you.
I am here to build with you. Let's help each other.
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Re: Hooks + Admin Configuration [how to?]

Post 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
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Re: Hooks + Admin Configuration [how to?]

Post 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.
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Re: Hooks + Admin Configuration [how to?]

Post by PiLLaO »

Nobody can bring me a little help? I'm not asking for code, only for the way to proceed...
User avatar
burt
Core Team
Posts: 4550
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Hooks + Admin Configuration [how to?]

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
Omar_one
Senior Contributor
Posts: 676
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: Hooks + Admin Configuration [how to?]

Post 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())
        ");
    }
}
}
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Hooks + Admin Configuration [how to?]

Post 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
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Re: Hooks + Admin Configuration [how to?]

Post 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
PiLLaO
Contributor
Posts: 107
Joined: Thu Nov 05, 2020 9:28 pm
Phoenix Version: v1.1.0.6
Has thanked: 53 times
Been thanked: 11 times

Re: Hooks + Admin Configuration [how to?]

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply