Hi,

Have a client who wishes to be sent a special email only when the customer has left a comment on the order. I'm sure that i can do this with either CA or rules in D6 by creating a custom template or just by using tokens but i have no idea how to format the condition part as i'm no use with PHP and i am guessing i'll need some custom PHP to recognise whether an [order-comment] has been left or not.

Can anyone help with the PHP part?

Thanks

Comments

John Carbone’s picture

Conditional Actions/Rules probably won't do this (I don't think anyway). But it should only be a few lines of PHP in a custom module to get it to work. I know you're not comfortable with PHP, but it's not a ton of work to get this going. Hopefully this can get you going and you can take it from here.

Off the top of my head here's what I'd do:
If you have a custom site module going add hook_order (called by Ubercart) to it so that when the order is submitted you can react and check for comments. The code below is more pseudocode than anything though. You'll have to figure out the variables and look at the functions/links below to get it going but this is a start anyway. Hope it helps!

//@see http://www.ubercart.org/docs/api/hook_order

function MYMODULE_order($op, &$arg1, $arg2) {
  switch ($op) {
    case 'submit':
      // check if the user left a comment, I don't know the array structure but it would be something like...
      if (isset($arg1['comment']) && !empty($arg1['comment'])) {
        // mail the comment. 
        $params['comment'] = $arg1['comment'];
        // add additional params for a link to the order, etc. Then...
        // trigger the message to be sent
        drupal_mail('MYMODULE', 'order_comment', 'owner@thissite.com', 'en', $params);
      }
      break;
  }
}

//See http://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail/6 for exact syntax
// this is invoked by calling drupal_mail above. Use it to fill out your message before it gets sent
function MYMODULE_mail($key, &$message, $params) {
    switch($key) {
      case 'order_comment':
        $message['subject'] = t('order comment');
        $message['body'][] = t($params['comment']);
        break;
    }
  }
?>