You are here

function uc_notify_order_update in Ubercart 5

File

uc_notify/uc_notify.module, line 367
Handles configuration and execution of email notifications.

Code

function uc_notify_order_update($form_id, $form_values) {
  $order = uc_order_load($form_values['order_id']);
  if ($order !== FALSE && $form_values['notify']) {
    if (!variable_get('uc_notify_order_update_enabled', TRUE)) {
      drupal_set_message(t('Order update e-mail notifications are currently disabled.'));
      return;
    }

    // Get the update e-mail body.
    $body = variable_get('uc_notify_order_update_body', uc_get_message('order_update_email'));

    // Convert tokens to their values.
    $body = token_replace_multiple($body, array(
      'global' => NULL,
      'order' => $order,
    ));
    $subject = variable_get('uc_notify_order_update_subject', t('Order #[order-id] Update'));
    $subject = token_replace_multiple($subject, array(
      'global' => NULL,
      'order' => $order,
    ));
    $email_to = $order->primary_email;
    $headers = uc_notify_headers();
    $sent = drupal_mail('order_comment', $order->primary_email, check_plain($subject), check_markup($body, variable_get('uc_notify_order_update_format', 3), FALSE), uc_store_email_from(), uc_notify_headers());
    if ($sent) {
      $changes[] = t('Customer notified of order update.');
    }
    else {
      $changes[] = t('Email notification to @email failed.', array(
        '@email' => $order->primary_email,
      ));
    }
    uc_order_log_changes($order->order_id, $changes);
  }
}