You are here

function uc_order_history in Ubercart 7.3

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

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

This function is deprecated; this listing is now provided by Views.

Parameters

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

File

uc_order/uc_order.admin.inc, line 877
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();
  $query = db_select('uc_orders', 'o');
  $o_order_id = $query
    ->addField('o', 'order_id');
  $o_created = $query
    ->addField('o', 'created');
  $o_status = $query
    ->addField('o', 'order_status');
  $o_total = $query
    ->addField('o', 'order_total');
  $o_uid = $query
    ->addField('o', 'uid');
  $query
    ->condition($o_uid, $user->uid)
    ->condition($o_status, uc_order_status_list('general', TRUE), 'IN');
  $count_query = $query
    ->countQuery();
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $os = $query
    ->leftJoin('uc_order_statuses', 'os', 'o.order_status = os.order_status_id');
  $op = $query
    ->leftJoin('uc_order_products', 'op', 'o.order_id = op.order_id');
  $os_title = $query
    ->addField('os', 'title');
  $op_products = $query
    ->addExpression('SUM(op.qty)', 'products');
  $query
    ->groupBy('o.order_id')
    ->groupBy('o.created')
    ->groupBy('os.title')
    ->groupBy('o.order_total')
    ->groupBy('o.order_status')
    ->groupBy('o.uid')
    ->orderByHeader($header)
    ->limit(20);
  $query
    ->setCountQuery($count_query);
  $result = $query
    ->execute();

  // Build a table based on the customer's orders.
  foreach ($result as $order) {
    $link = l($order->order_id, 'user/' . $user->uid . '/orders/' . $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, 'uc_store'),
      ),
      array(
        'data' => $link,
      ),
      array(
        'data' => check_plain($order->title),
      ),
      array(
        'data' => !is_null($order->products) ? $order->products : 0,
        'align' => 'center',
      ),
      array(
        'data' => array(
          '#theme' => 'uc_price',
          '#price' => $order->order_total,
        ),
        'align' => 'right',
      ),
    );
  }
  $build = array();
  $build['orders'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'uc-order-history',
      ),
    ),
    '#empty' => t('No orders available.'),
  );
  $build['pager'] = array(
    '#theme' => 'pager',
    '#element' => 0,
    '#weight' => 5,
  );
  return $build;
}