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.
Hooks + Admin Configuration [how to?]
- burt
- Core Team
- Posts: 4546
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Hooks + Admin Configuration [how to?]
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.
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?]
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
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
- burt
- Core Team
- Posts: 4546
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Hooks + Admin Configuration [how to?]
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.
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.
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?]
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
- : Buy Me A Beverage
- Has thanked: 70 times
- Been thanked: 152 times
Re: Hooks + Admin Configuration [how to?]
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
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
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?]
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.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.
The cuestion was, if I need to make it as a module, what kind of module need to use, because not payment, shipping, content...
Thanks you so much, you give me more than I asking for, thanksOmar_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()) "); } } }
-
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?]
Thanks rainer, I'll take a look laterraiwa 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