You are here

function uc_order_token_values in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_order/uc_order.module \uc_order_token_values()

Implementation of hook_token_values(). (token.module)

File

uc_order/uc_order.module, line 317

Code

function uc_order_token_values($type, $object = NULL) {
  switch ($type) {
    case 'order':
      $order = $object;
      if (isset($_SESSION['new_user']) && is_array($_SESSION['new_user'])) {
        $values['new-username'] = check_plain($_SESSION['new_user']['name']);
        $values['new-password'] = check_plain($_SESSION['new_user']['pass']);
      }
      else {
        $values['new-username'] = '';
        $values['new-password'] = '';
      }
      $values['order-id'] = $order->order_id;
      $values['order-uid'] = $order->uid;
      $values['order-url'] = url('user/' . $order->uid . '/order/' . $order->order_id, NULL, NULL, TRUE);
      $values['order-link'] = l($order->order_id, $values['order-url']);
      $values['order-admin-url'] = url('admin/store/orders/' . $order->order_id, NULL, NULL, TRUE);
      $admin_url = url('admin/store/orders/' . $order->order_id, NULL, NULL, TRUE);
      $values['order-admin-link'] = l($order->order_id, $admin_url);
      if (is_array($order->line_items)) {
        foreach ($order->line_items as $key => $value) {
          if ($value['type'] == 'subtotal') {
            $subtotal = uc_currency_format($order->line_items[$key]['amount']);
          }
          if ($value['type'] == 'shipping' && is_null($ship_method)) {
            $ship_method = $value['title'];
          }
        }
      }
      $values['order-subtotal'] = $subtotal;
      $values['order-total'] = uc_currency_format($order->order_total);
      $values['order-email'] = check_plain($order->primary_email);
      $values['order-shipping-address'] = uc_order_address($order, 'delivery');
      $values['order-shipping-phone'] = check_plain($order->delivery_phone);
      $values['order-shipping-method'] = is_null($ship_method) ? t('Standard delivery') : $ship_method;
      $values['order-billing-address'] = uc_order_address($order, 'billing');
      $values['order-billing-phone'] = check_plain($order->billing_phone);
      if (variable_get('uc_customer_list_address', 'billing') == 'shipping') {
        $values['order-first-name'] = check_plain($order->delivery_first_name);
        $values['order-last-name'] = check_plain($order->delivery_last_name);
      }
      else {
        $values['order-first-name'] = check_plain($order->billing_first_name);
        $values['order-last-name'] = check_plain($order->billing_last_name);
      }
      $result = db_result(db_query("SELECT message FROM {uc_order_comments} WHERE order_id = %d AND uid = 0 ORDER BY created DESC LIMIT 1", $order->order_id));
      $values['order-comments'] = empty($result) ? t('<i>No comments left.</i>') : check_plain($result);
      $result = db_result(db_query("SELECT message FROM {uc_order_comments} WHERE order_id = %d AND uid > 0 ORDER BY created DESC LIMIT 1", $order->order_id));
      $values['order-last-comment'] = empty($result) ? t('<i>No comment found.</i>') : check_plain($result);
      $values['order-status'] = uc_order_status_data($order->order_status, 'title');
      $values['order-date-created'] = format_date($order->created, 'small');
      $values['order-date-modified'] = format_date($order->modified, 'small');
      break;
  }
  return $values;
}