Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Help Using Hooks In Custom Addon Rate Topic   - - - - -

 

Posted 23 September 2016 - 03:33 PM #1

Hi,

 

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:

<?xml version="1.0"?>

<addon scheme='2.0'>
    <id>testaddon</id>
    <version>1.0</version>
    <name>Test Addon</name>
    <description>test addon</description>
    <priority>100500</priority>
    <status>active</status>
</addon>

init.php

<?php

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

fn_register_hooks(
    "add_to_cart",
    "update_order"
);

func.php

<?php

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

function fn_testaddon_update_order($order, $order_id){
    var_dump("hi");
    var_dump($order);
    die();
}

function fn_testaddon_add_to_cart($cart, $product_id, $_id)
{
    var_dump($cart);
    die();
}


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10,142 posts

Posted 24 September 2016 - 02:31 AM #2

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().

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 16,142 posts

Posted 26 September 2016 - 07:00 AM #3

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

with

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

Then clear cache and check the result


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration

Certified CS-Cart RU Developer | Сертифицированный разработчик на CS-Cart Русская Версия

 

Posted 26 September 2016 - 08:19 AM #4

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:

https://www.dropbox.....18.34.png?dl=0

 

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



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10,142 posts

Posted 26 September 2016 - 05:59 PM #5

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 <!-- name_of_id --></div>

 

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 16,142 posts

Posted 27 September 2016 - 07:05 AM #6

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));
die();

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration

Certified CS-Cart RU Developer | Сертифицированный разработчик на CS-Cart Русская Версия

 

Posted 06 October 2016 - 08:35 AM #7

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".



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10,142 posts

Posted 06 October 2016 - 04:07 PM #8

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • simon84
  • Newbie
  • Trial users
  • Join Date: 04-Jun 17
  • 7 posts

Posted 12 January 2018 - 11:09 AM #9

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 https://helpdesk.cs-cart.com/index.phpfor 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?



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10,142 posts

Posted 12 January 2018 - 06:27 PM #10

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.