You are here

function uc_order_token_values in Ubercart 6.2

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

Implements hook_token_values(). (token.module)

File

uc_order/uc_order.module, line 420

Code

function uc_order_token_values($type, $object = NULL) {
  $values = array();
  switch ($type) {
    case 'order':
      $order = $object;
      $values['new-username'] = isset($order->data['new_user']['name']) ? check_plain($order->data['new_user']['name']) : '';
      $values['new-password'] = isset($order->password) ? $order->password : t('Your password');
      $values['order-id'] = $order->order_id;
      $values['order-uid'] = $order->uid;
      $values['order-url'] = url('user/' . $order->uid . '/order/' . $order->order_id, array(
        'absolute' => TRUE,
      ));
      $values['order-link'] = l($order->order_id, $values['order-url']);
      $values['order-admin-url'] = url('admin/store/orders/' . $order->order_id, array(
        'absolute' => TRUE,
      ));
      $admin_url = url('admin/store/orders/' . $order->order_id, array(
        'absolute' => TRUE,
      ));
      $values['order-admin-link'] = l($order->order_id, $admin_url);
      $subtotal = '';
      $subtotal_raw = 0;
      if (is_array($order->line_items)) {
        foreach ($order->line_items as $key => $value) {
          if ($value['type'] == 'subtotal') {
            $context = array(
              'revision' => 'formatted',
              'type' => 'line_item',
              'subject' => array(
                'order' => $order,
                'line_item' => $order->line_items[$key],
              ),
            );
            $subtotal = uc_price($order->line_items[$key]['amount'], $context);
            $context['revision'] = 'original';
            $subtotal_raw = uc_price($order->line_items[$key]['amount'], $context);
          }
          if ($value['type'] == 'shipping' && !isset($ship_method)) {
            $ship_method = $value['title'];
          }
        }
      }
      $values['order-subtotal'] = $subtotal;
      $values['order-subtotal-raw'] = $subtotal_raw;
      $context = array(
        'revision' => 'formatted-original',
        'type' => 'order_total',
        'subject' => array(
          'order' => $order,
        ),
      );
      $values['order-total'] = uc_price($order->order_total, $context);
      $context['revision'] = 'original';
      $values['order-total-raw'] = uc_price($order->order_total, $context);
      $values['order-email'] = check_plain($order->primary_email);
      $values['order-email-raw'] = $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'] = !isset($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_range("SELECT message FROM {uc_order_comments} WHERE order_id = %d AND uid = 0 ORDER BY created DESC", $order->order_id, 0, 1));
      $values['order-comments'] = empty($result) ? t('<i>No comments left.</i>') : check_plain($result);
      $result = db_result(db_query_range("SELECT message FROM {uc_order_comments} WHERE order_id = %d AND uid > 0 ORDER BY created DESC", $order->order_id, 0, 1));
      $values['order-last-comment'] = empty($result) ? t('<i>No comment found.</i>') : check_plain($result);
      $values['order-last-comment-raw'] = empty($result) ? t('<i>No comment found.</i>') : $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;
}