MichaelScofield Posted May 14, 2009 Share Posted May 14, 2009 Since I upgraded to v4 I can't print this array. Instead of displaying all the values in the array it only displays one number, which is the order number. Here is the code I have: <?php function create_store($vars) { print_r ("<pre>"); print_r ($vars); print_r ("</pre>"); } add_hook("AfterShoppingCartCheckout",1,"create_store",""); ?> Is this a bug or am I doing something wrong? 0 Quote Link to comment Share on other sites More sharing options...
MichaelScofield Posted May 14, 2009 Author Share Posted May 14, 2009 Not sure why it wasn't working. It's working now. But one thing is different in v4: if you want to print a value from the array you need to do it like this: print_r ($vars[1]["addons"]); Doing it like in v3.8 - print_r ($vars["addons"]); - won't work 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted May 14, 2009 Share Posted May 14, 2009 Its something your doing wrong. It has changed slightly from the old way. If you look at the wiki at the bottom you will see the variables passed to each hook function. eg... <?php function create_store($OrderID, $OrderNumber, $InvoiceID, $Products, $Addons, $Domains) { echo"<pre>"; print_r($OrderID); print_r($OrderNumber); print_r($InvoiceID); print_r($Products); print_r($Addons); print_r($Domains); echo"</pre>"; } add_hook("AfterShoppingCartCheckout",1,"create_store",""); ?> 0 Quote Link to comment Share on other sites More sharing options...
ChrisGooding Posted May 27, 2009 Share Posted May 27, 2009 when using this, where does the oiutput display? I know this may sound a stupid question, but I am trying to find out what is given in $params for the hook AfterModuleCreate and am using the below: function actionhook_AfterModulecreate($vars) { # This function runs when a module suspension command completes success print_r($params); } Thing is it just doesnt seem to display anything..... do i need to get it to print somewhere, or have it email them? 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted May 27, 2009 Share Posted May 27, 2009 I would recommend just capturing the output and throwing it into a text file to see whats being outputted, etc. 0 Quote Link to comment Share on other sites More sharing options...
ChrisGooding Posted May 27, 2009 Share Posted May 27, 2009 Ok,. realised I was using an old way as a method of using the hook, although I think I now am using it correctly, I still dont get any output (that i know of), using the below: <?php function show_params_used($params) { echo"<pre>"; print_r($params); echo"</pre>"; } add_hook("actionhook_AfterModuleSuspend",1,"show_params_used",""); ?> 0 Quote Link to comment Share on other sites More sharing options...
ChrisGooding Posted May 27, 2009 Share Posted May 27, 2009 must have posted at the same time, sorry. How would I go about that, I am not the best coder, usually cobbling stuff together? Oh and thanks for the suggestion 0 Quote Link to comment Share on other sites More sharing options...
ChrisGooding Posted May 28, 2009 Share Posted May 28, 2009 I have put the following together, but for some reason simply uploading the file to the server stops the entire whmcs install working :shock: Surely my code isn't that bad?? Heres what I have - <?php # This function runs when a module create command completes success$ $outputFile = "moduleparams.txt"; $fh = fopen($outputFile, 'w') or die("can't open file"); add_hook("actionhook_AfterModuleSuspend",1,"show_params_used",""); function show_params_used($params) { fwrite($fh, $params); fclose($fh); } ?> 0 Quote Link to comment Share on other sites More sharing options...
rob897 Posted September 17, 2009 Share Posted September 17, 2009 I just have it email me the params: function DoSomething($params) { $msg = ''; foreach($params as $param) { $msg .= $param."\n"; } mail("jdoe@gmail.com","Hook DoSomething",$msg,"FROM:test@test.com"); } 0 Quote Link to comment Share on other sites More sharing options...
MichaelScofield Posted September 17, 2009 Author Share Posted September 17, 2009 Actually, I had to replace hookfunctions.php with the one that Matt provided and it fixed this problem. 0 Quote Link to comment Share on other sites More sharing options...
Waqas Saeed Posted August 30, 2020 Share Posted August 30, 2020 How do we usually test the hook ? what is the best way to test the hook as I have to work with DB. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.