v1ktor Posted September 17, 2013 Share Posted September 17, 2013 I'm trying to create a ticket when order is created, but for some reason I can't get hook to work. Would appreciate some feedback. <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); function hook_newOrderTicket($vars) { $ordernum = $vars['ordernumber']; $command = "openticket"; $adminuser = "adminusername"; //$values["clientid"] = "1"; $values["deptid"] = "5"; $values["subject"] = "Process Order #".$ordernum; $values["message"] = "New order has been submitted. Order #".$ordernum." Review order information and begin processing it according to appropriate instructions. If you have any questions, contact your immediate supervisor."; $values["priority"] = "High"; $values["noemail"] = "true"; $results = localAPI($command,$values,$adminuser); } add_hook("AfterShoppingCartCheckout",1,"hook_newOrderTicket"); ?> 0 Quote Link to comment Share on other sites More sharing options...
SoluteDNS Posted September 17, 2013 Share Posted September 17, 2013 Try: After: $results = localAPI($command,$values,$adminuser); Add: var_dump($results); die; You now should see the response from the api what can help you troubleshooting. When you found the problem do not forget to remove the added code! 0 Quote Link to comment Share on other sites More sharing options...
v1ktor Posted September 17, 2013 Author Share Posted September 17, 2013 Thanks SoluteDNS, here's what it was: array(2) { ["result"]=> string(5) "error" ["message"]=> string(51) "Name and email address are required if not a client" } I'm assuming this means I need to pass clientid to create a ticket? I wasn't sure how to get clientid using AfterShoppingCartCheckout hook when documentation did not say it had clientid variable available for this hook. Any feedback would be much appreciated. 0 Quote Link to comment Share on other sites More sharing options...
SoluteDNS Posted September 17, 2013 Share Posted September 17, 2013 (edited) If you are using a name and e-mail you still need to set the clientid attribute to 0. Else you need to retrieve the clientid for which you want to open a ticket. The hook point you are using is returning a orderid, you can use this (or the invoiceid) to retrieve the client id from the database. To call a returned variable from the hook point use: $orderid = $vars['orderid']; For the database part you could use this (I did not test this): $table = "tblorders"; $fields = "id,userid"; $where = array("id"=>$orderid); $result = select_query($table,$fields,$where); $data = mysql_fetch_array($result); $client_id = $data['userid']; http://docs.whmcs.com/SQL_Helper_Functions Edited September 17, 2013 by SoluteDNS Adding database example 0 Quote Link to comment Share on other sites More sharing options...
v1ktor Posted September 17, 2013 Author Share Posted September 17, 2013 Thanks, that's right on the money! For anyone looking to use this for their WHMCS, here's what to do: Create a file inslude /includes/hooks/ and put this code in there. <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); function hook_newOrderTicket($vars) { $orderid = $vars['orderid']; $table = "tblorders"; $fields = "id,userid"; $where = array("id"=>$orderid); $result = select_query($table,$fields,$where); $data = mysql_fetch_array($result); $client_id = $data['userid']; $command = "openticket"; $adminuser = "adminusername"; $values["clientid"] = $client_id; $values["deptid"] = "5"; // this is support department id where ticket will be created $values["subject"] = "Process Order #".$orderid; $values["message"] = "New order has been submitted. Order #".$orderid." Review order information and begin processing it according to appropriate instructions. If you have any questions, contact your immediate supervisor."; $values["priority"] = "High"; //ticket priority - low, medium, high $values["noemail"] = true; //setting this to false will send client email above $results = localAPI($command,$values,$adminuser); var_dump($results); die; } add_hook("ShoppingCartCheckoutCompletePage",1,"hook_newOrderTicket"); ?> 0 Quote Link to comment Share on other sites More sharing options...
SoluteDNS Posted September 18, 2013 Share Posted September 18, 2013 Great you have this working! For people copying this code, you might want to remove this part: var_dump($results); die; 0 Quote Link to comment Share on other sites More sharing options...
PHPCore Posted September 18, 2013 Share Posted September 18, 2013 Thanks for this, I hadn't thought of it before. I have now added this to my WHMCS installation. 0 Quote Link to comment Share on other sites More sharing options...
v1ktor Posted September 19, 2013 Author Share Posted September 19, 2013 Great you have this working! For people copying this code, you might want to remove this part: var_dump($results); die; Thanks, yes, I copied it before I had a chance to remove var_dump, and unfortunately, I can't edit my post here. 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.