GoogieHost Posted March 2, 2019 Share Posted March 2, 2019 Hi, We would like to set up email templates when the order is rejected/cancelled due to any issues, we would like to send customer's email notification with templates. Is there any guide to setup this thing ? 0 Quote Link to comment Share on other sites More sharing options...
GoogieHost Posted March 4, 2019 Author Share Posted March 4, 2019 @brian! @steven99 @WHMCS ChrisD Do you have any idea how to do that? 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 4, 2019 Share Posted March 4, 2019 Personally for such an item, I would think opening a ticket would be better but tickets don't do templates. Would be possible to do by grabbing a template from the db and tossing it in to smarty with the order variables. If there is enough demand I will do the template part later on. <?php /** @author steven99 **/ add_hook('CancelOrder', 1, function($vars) { if (isset($vars['orderid']) and is_numeric($vars['orderid'])) // should be there, but defensive coding mode active { $results = localAPI('GetOrders', array('id' => $vars['orderid'])); if ($results and isset($results['result']) AND $results['result'] =='success' and isset($result['order']['order'][0]])) { $Order = $result['order']['order'][0]; // supplied one id, get oen order //got the cancelled order, now what? //open ticket to client $command = "openticket"; $values["clientid"] = $Order['userid']; $values["deptid"] = "2"; $values["subject"] = "Order Cancelled"; $values["message"] = "Hello, Your order has been cancelled. This ticket is being opened to further communicate this with you." ; $values["priority"] = "Medium"; $values['serviceid'] = (isset($Order['lineitems']['lineitem'][0]['relid']) ? $Order['lineitems']['lineitem'][0]['relid'] : null); // assign ticket ot first service in order $results = localAPI($command,$values); } } }); 0 Quote Link to comment Share on other sites More sharing options...
GoogieHost Posted March 5, 2019 Author Share Posted March 5, 2019 @steven99 In my case it is necessary, tickets wouldn't resolve our problem 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 5, 2019 Share Posted March 5, 2019 Could you go in to more detail? 0 Quote Link to comment Share on other sites More sharing options...
GoogieHost Posted March 5, 2019 Author Share Posted March 5, 2019 35 minutes ago, steven99 said: Could you go in to more detail? We don't accept orders automatically, We want to send email notification if Pending order marked as cancelled with Template. (We will explain possible reasons why the order wasnt activated 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 5, 2019 Share Posted March 5, 2019 Not sure how accepting orders affects this the above as the hook fires if the system cancels or if an admin cancels. Well, using the same hook above and using the sendemail API function would give you a template option. Either way to get the functionality you want requires the usage of a hook. 0 Quote Link to comment Share on other sites More sharing options...
GoogieHost Posted March 5, 2019 Author Share Posted March 5, 2019 I have tested it but it only fires the email if cron runs. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 5, 2019 Share Posted March 5, 2019 Then something is not right with your hook as I have just tested the following hook and it sends out the notice when i cancel an order. <?php /** @author steven99 **/ add_hook('CancelOrder', 1, function($vars) { $TicketOrEmail = "email"; // set to "email" for just email notification $EmailTemplateName = "Order Cancelled"; // set to name of the email template to use if (isset($vars['orderid']) and is_numeric($vars['orderid'])) // should be there, but defensive coding mode active { $results = localAPI('GetOrders', array('id' => $vars['orderid'])); if ($results and isset($results['result']) AND $results['result'] == 'success' and isset($results['orders']['order'][0])) { $Order = $results['orders']['order'][0]; // supplied one id, get oen order //got the cancelled order, now what? if ($TicketOrEmail == "ticket") { //open ticket to client $command = "openticket"; $values["clientid"] = $Order['userid']; $values["deptid"] = "1"; $values["subject"] = "Order Cancelled"; $values["message"] = "Hello, Your order has been cancelled. This ticket is being opened to further communicate this with you." ; $values["priority"] = "Medium"; $values['serviceid'] = (isset($Order['lineitems']['lineitem'][0]['relid']) ? $Order['lineitems']['lineitem'][0]['relid'] : null); // assign ticket ot first service in order $results = localAPI($command,$values); } elseif ($TicketOrEmail == "email") { $command = 'SendEmail'; $postData = array( 'messagename' => $EmailTemplateName, 'id' => (isset($Order['lineitems']['lineitem'][0]['relid']) ? $Order['lineitems']['lineitem'][0]['relid'] : null), 'customvars' => base64_encode(serialize(array("Order"=>$Order))), ); $results = localAPI($command,$postData); } /* * Order array; * Array ( [id] => 131 [ordernum] => 3244838540 [userid] => 4 [contactid] => 0 [date] => 2019-03-04 23:17:33 [nameservers] => [transfersecret] => [renewals] => [promocode] => [promotype] => [promovalue] => [orderdata] => a:0:{} [amount] => 5.11 [paymentmethod] => yourpayment [invoiceid] => 122 [status] => Pending [ipaddress] => d [fraudmodule] => [fraudoutput] => [notes] => [paymentmethodname] => gatewayname [paymentstatus] => Unpaid [name] => test [currencyprefix] => $ [currencysuffix] => USD [frauddata] => [lineitems] => Array ( [lineitem] => Array ( [0] => Array ( [type] => product [relid] => 77 [producttype] => Hosting Account [product] => test [domain] => [billingcycle] => Monthly [amount] => WHMCS\View\Formatter\Price Object ( [price:protected] => 5.11 [currency:protected] => Array ( [id] => 1 [code] => USD [prefix] => $ [suffix] => USD [format] => 1 [rate] => 1.00000 ) [defaultFormat:protected] => {PREFIX}{PRICE}{SUFFIX} [defaultCurrencyDescriptor:protected] => Array ( [format] => 1 [prefix] => [suffix] => ) ) [status] => Pending ) ) ) ) */ } } }); Though for some reason the sendemail api isn't accepting the custom vars and doing {debug} in the email template it doesn't even show there. If I have more time I'll look further at this. 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.