Help Using Hook

Hi,

I have some modification in fn.cart (app/functions) and, of course, it breaks each time I update CS-Cart. I know I have to use Hooks instead of modifiying the core, but I am too weak in code and after reading informations about hooks, I still cannot do it :(

Is there anyone that can help me and explain how to make my changes in fn.cart using hooks instead of changing the core ?

I need to replace the following code :

$paid_statuses = array('P', 'C');
by this one :
$paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');

Thank you in advance for your help :)

Hello

You can use hook "get_orders_totals"

The function that supports hook should look like this:

function fn_YOUR_ADDON_NAME_get_orders_totals(&$paid_statuses, $join, $condition, $group)

{

$paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');

}

Remember to give the appropriate entry in the init.php file

Best regards

Robert

The func.php file should be located here

app/addons/YOUR_ADDON_NAME/func.php

The content of the app/addons/YOUR_ADDON_NAME/init.php file should be

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

fn_register_hooks(
‘get_orders_totals’
);

Do not forget about addon.xml file. Check example in the my_changes addon

Thanks.

So if I understand, I have to create a repertory in addon with my add-on name.

Inside of it, I put the addon.xml file, init.php file that include the information of the hook and the func.php file that include the changes.

Do I have then to install the add-on in backend or the hook is automatically started ?

And last question, I have some mods in /design/backend/templates/addons/discussion/views/discussion_manager/components/allow_discussion.tpl

In that case, it seems there is no hook in that file. Can I make the change using hook or is it impossible ?

Do I have then to install the add-on in backend or the hook is automatically started ?

Addon should be installed and has Active status

And last question, I have some mods in /design/backend/templates/addons/discussion/views/discussion_manager/components/allow_discussion.tpl

In that case, it seems there is no hook in that file. Can I make the change using hook or is it impossible ?

This template does not have hooks. So you should override it

Does not work :(

I have :

- Created directory **ADD-ON NAME** in /app/addons

- Created addon.xml

ADD-ON NAME
1.0
100500
0
MULTIVENDOR,ULTIMATE
fr
- created init.php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
fn_register_hooks(
'get_orders_totals'
);
- created func.php
function fn_ADD-ON NAME_get_orders_totals(&$paid_statuses, $join, $condition, $group)
{
$paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');
}
After installation, it went to service unavailable for a while. When site comes back, add-on is installed and activated, but it does not show any changes.
Did I made everything right ?

Hello

Write what the real addon_id is

What are you written between

ADD-ON NAME

Best regards

Robert

When you see Service unavailable error, check page source code (Ctrl + U) to see error text

Hello

Write what the real addon_id is

What are you written between

ADD-ON NAME

Best regards

Robert

Thanks for answer Robert !

I have put ADD-ON NAME in the post for the forum. In my files, it's already replaced by the add-on name I used (fncartmod).

Put the following code to the function to see if it is called

fn_print_r('test');