You are here

function uc_store_customer_orders in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_store/uc_store.admin.inc \uc_store_customer_orders()
1 string reference to 'uc_store_customer_orders'
uc_store_menu in uc_store/uc_store.module
Implementation of hook_menu().

File

uc_store/uc_store.module, line 724
Contains global Ubercart functions and store administration functionality.

Code

function uc_store_customer_orders($uid) {
  $result = pager_query("SELECT * FROM {uc_orders} WHERE uid = %d AND " . "order_status IN " . uc_order_status_list('general', TRUE) . " ORDER BY created DESC", 50, 0, NULL, $uid);
  $header = array(
    t('View'),
    t('Order ID'),
    t('Date'),
    t('Billing name'),
    t('Shipping name'),
    t('Items'),
    t('Total'),
  );
  if (db_num_rows($result) == 0) {
    $rows[] = array(
      array(
        'data' => t('No orders found.'),
        'colspan' => 7,
      ),
    );
  }
  else {
    $totals = array(
      'orders' => 0,
      'items' => 0,
      'total' => 0,
    );
    while ($order = db_fetch_object($result)) {
      $icons = l(uc_store_get_icon('file:order_view'), 'admin/store/orders/' . $order->order_id, array(
        'title' => t("View order !order_id.", array(
          '!order_id' => $order->order_id,
        )),
      ), NULL, NULL, FALSE, TRUE) . l(uc_store_get_icon('file:order_edit'), 'admin/store/orders/' . $order->order_id . '/edit', array(
        'title' => t("Edit order !order_id.", array(
          '!order_id' => $order->order_id,
        )),
      ), NULL, NULL, FALSE, TRUE);
      $bname = ucfirst($order->billing_first_name) . ' ' . ucfirst($order->billing_last_name);
      $sname = ucfirst($order->delivery_first_name) . ' ' . ucfirst($order->delivery_last_name);
      $result2 = db_query("SELECT COUNT(*) FROM {uc_order_products} WHERE " . "order_id = %d", $order->order_id);
      $item_count = db_fetch_array($result2);
      $totals['orders'] += 1;
      $totals['items'] += $item_count['COUNT(*)'];
      $totals['total'] += $order->order_total;
      $rows[] = array(
        'data' => array(
          array(
            'data' => $icons,
          ),
          array(
            'data' => $order->order_id,
          ),
          array(
            'data' => format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
          ),
          array(
            'data' => check_plain($bname),
          ),
          array(
            'data' => check_plain($sname),
          ),
          array(
            'data' => $item_count['COUNT(*)'],
          ),
          array(
            'data' => uc_currency_format($order->order_total),
            'nowrap' => 'nowrap',
          ),
        ),
        'id' => 'order-' . $order->order_id,
      );
    }
  }
  uc_add_js(drupal_get_path('module', 'uc_store') . '/uc_store.js');
  $output = '<p>' . l(t('Create an order for this customer.'), 'admin/store/orders/create/' . $uid) . '</p>';
  $output .= '<p>' . t('!totals_orders orders shown match that account with !totals_items items purchased and !totals_total spent:', array(
    '!totals_orders' => $totals['orders'],
    '!totals_items' => $totals['items'],
    '!totals_total' => uc_currency_format($totals['total']),
  )) . '</p>' . theme('table', $header, $rows, array(
    'width' => '100%',
    'class' => 'uc-cust-orders-table',
  )) . '<br />' . theme_pager(NULL, 50);
  return $output;
}