Jump to content

Help with Simple openticket internal API


v1ktor

Recommended Posts

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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by SoluteDNS
Adding database example
Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated