Jump to content
GoogieHost

Email Notification on Order Cancelled/Terminated

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites

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

        }
    }
});

 

 

 

 

Share this post


Link to post
Share on other sites
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 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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