Help Using Hooks In Custom Addon


I'm trying to do this in a completely new plugin, but, I can't seem to get any data back in any of my tests, not any of them! I've tried to uninstall/reinstall the plugin, I've tried a simple hook like "add to cart", nothing appears on the page or in the network tab. Can anyone suggest what I am doing wrong here?

Thanks in advance

Here's my addon.xml:

    Test Addon
    test addon


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



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

function fn_testaddon_update_order($order, $order_id){

function fn_testaddon_add_to_cart($cart, $product_id, $_id)

These are ajax requests so you won’t see anything on screen. But you should see it in the response section of your browser inspector if you didn’t have the die().

To check adding to cart, open the config.local.php file and replace:

'disable_dhtml' => false, // Disable Ajax-based pagination and Ajax-based "Add to cart" button


'disable_dhtml' => true, // Disable Ajax-based pagination and Ajax-based "Add to cart" button

Then clear cache and check the result

Thanks for getting back to me both,

I've removed the die, though unfortunately that did not reveal anything in the browser's inspector network tab.

On the add to cart function I have looking in the network table, the add to cart returns a POST request, which contains the markup for the entire webpage, but, my var_dump does not exists!

On the update order I look in the network tab, and, all I get is a POST request which contains JSON data:

I still cannot get any information back. Any further ideas?

The way cs-cart does AJAX requests is that the whole page is re-rendered and resent. JS on the client side looks for the ID of the "result_ids" and requires a closing

Verify your addon is in fact installed and enabled and then I'd so a quick die("Got here") at the end of your func.php to quickly assess that your addon is being invoked.

If the contents you list above are correct then you should see your vardump in the response. But as Ecom states, it is easier if you disable the ajax request for the cart.

If you are not familiar with the browser console, you can use the default function which display notifications:

fn_set_notification(‘N’, __(‘notice’), var_export($order, true));

Thank you guys, after all that, it appears that I was using the incorrect hook!

I was expecting "update_order" to fire when I changed the status of the order on the order listing page.

Turns out "update_order" will only fire if you go into an order, click the "edit order" link, then save!

The hook that appears to fire in every situation that you expect is "change_order_status".

Yes, change_order_status is probably the most widely used hook in the system since you can fire off events from this related to almost all order activities.

Facing a related problem: in CsCart 4.2.2, it seems that neither the hook update_option_combination_pre nor update_option_combination_post is ever triggered when updating inventories of product options from the backend. While in the source code of fn.catalog.php, none of these hooks is listed in CsCart hook base this version, as well there seems to be some issue with duplicate hooks which has been resolved in v 4.3.

To make this work, is there a central source code file registering hooks declared in the code by fn_set_hook('hook_name", $params)? Where can I find it to manually fix the potential bug on my end?

Not aware of any bug regarding duplicate hooks. If you are saying the the fn_set_hook('update_option_combination_pre',....) is not in your source base then this hook was added at a later version and is not supported in your version.

You can (in code) look at (I think but might be different) $registered_hooks = Registry::get('hooks'); This will tell you what hooks have been registered and what function (addon) they are registered to.