You are here

function uc_order_history in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_order/uc_order.module \uc_order_history()
  2. 7.3 uc_order/uc_order.admin.inc \uc_order_history()

Returns the sortable table listing of a customer's orders.

Parameters

$uid: The user ID whose orders you wish to list.

1 string reference to 'uc_order_history'
uc_order_menu in uc_order/uc_order.module
Implements hook_menu().

File

uc_order/uc_order.admin.inc, line 1048
Order administration menu items.

Code

function uc_order_history($user) {
  drupal_set_title(t('My order history'));
  $header = array(
    array(
      'data' => t('Date'),
      'field' => 'o.created',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Order #'),
      'field' => 'o.order_id',
    ),
    array(
      'data' => t('Status'),
      'field' => 'os.title',
    ),
    array(
      'data' => t('Products'),
      'field' => 'products',
    ),
    array(
      'data' => t('Total'),
      'field' => 'o.order_total',
    ),
  );
  $rows = array();
  $context = array(
    'revision' => 'themed-original',
    'type' => 'amount',
  );
  $result = pager_query("SELECT o.order_id, o.uid, o.created, os.title, SUM(op.qty) AS products, o.order_total AS total, o.order_status FROM {uc_orders} AS o LEFT JOIN {uc_order_statuses} AS os ON o.order_status = os.order_status_id LEFT JOIN {uc_order_products} AS op ON o.order_id = op.order_id WHERE o.uid = %d AND o.order_status IN " . uc_order_status_list('general', TRUE) . " GROUP BY o.order_id, o.uid, o.created, os.title, o.order_total, o.order_status" . tablesort_sql($header), 20, 0, "SELECT COUNT(*) FROM {uc_orders} WHERE uid = %d AND order_status NOT IN " . uc_order_status_list('specific', TRUE), $user->uid);

  // Build a table based on the customer's orders.
  while ($order = db_fetch_object($result)) {
    $context['subject'] = array(
      'order' => $order,
    );
    $link = l($order->order_id, 'user/' . $user->uid . '/order/' . $order->order_id);
    if (user_access('view all orders')) {
      $link .= '<span class="order-admin-icons">' . uc_order_actions($order, TRUE) . '</span>';
    }
    $rows[] = array(
      array(
        'data' => format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
      ),
      array(
        'data' => $link,
      ),
      array(
        'data' => check_plain($order->title),
      ),
      array(
        'data' => !is_null($order->products) ? $order->products : 0,
        'align' => 'center',
      ),
      array(
        'data' => uc_price($order->total, $context),
        'align' => 'right',
      ),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No orders available.'),
        'colspan' => 5,
      ),
    );
  }
  return theme('table', $header, $rows, array(
    'class' => 'uc-order-history',
  )) . theme('pager', NULL, 20, 0);
}