You are here

function uc_shipping_order_packages in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_order_packages()
  2. 7.3 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_order_packages()

Display a list of an order's packaged products.

1 string reference to 'uc_shipping_order_packages'
uc_shipping_menu in shipping/uc_shipping/uc_shipping.module
Implementation of hook_shipping_menu().

File

shipping/uc_shipping/uc_shipping.module, line 184
Organizes ordered products into packages and sets them up for shipment. Shipping method modules may add functionality to generate shipping labels and tracking numbers.

Code

function uc_shipping_order_packages($order_id) {
  $header = array(
    t('Package ID'),
    t('Products'),
    t('Shipping type'),
    t('Package type'),
    t('Shipment ID'),
    t('Tracking number'),
    t('Labels'),
    array(
      'data' => t('Actions'),
      'colspan' => 3,
    ),
  );
  $rows = array();
  $result = db_query("SELECT * FROM {uc_packages} WHERE order_id = %d", $order_id);
  while ($package = db_fetch_object($result)) {
    $row = array();
    $row[] = $package->package_id;
    $product_list = array();
    $result2 = db_query("SELECT op.order_product_id, pp.qty, op.title, op.model FROM {uc_packaged_products} AS pp LEFT JOIN {uc_order_products} AS op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = %d", $package->package_id);
    while ($product = db_fetch_object($result2)) {
      $product_list[] = $product->qty . ' x ' . check_plain($product->model);
    }
    $row[] = '<ul><li>' . implode('</li><li>', $product_list) . '</li></ul>';
    $row[] = strtr($package->shipping_type, '_', ' ');
    $row[] = check_plain($package->pkg_type);
    $row[] = isset($package->sid) ? l($package->sid, 'admin/store/orders/' . $order_id . '/shipments/' . $package->sid . '/view') : '';
    $row[] = isset($package->tracking_number) ? check_plain($package->tracking_number) : '';
    if ($package->sid && $package->label_image) {
      $method = db_result(db_query("SELECT shipping_method FROM {uc_shipments} WHERE sid = %d", $package->sid));
    }
    $row[] = isset($package->label_image) ? l(theme('imagecache', 'uc_thumbnail', $package->label_image, t('Shipping Label'), t('Shipping Label')), 'admin/store/orders/' . $order_id . '/shipments/labels/' . $method . '/' . $package->label_image, array(), null, null, false, true) : '';
    $row[] = l(t('edit'), 'admin/store/orders/' . $order_id . '/packages/' . $package->package_id . '/edit');
    $row[] = l(t('delete'), 'admin/store/orders/' . $order_id . '/packages/' . $package->package_id . '/delete');
    if ($package->sid) {
      $row[] = l(t('cancel shipment'), 'admin/store/orders/' . $order_id . '/packages/' . $package->package_id . '/cancel');
    }
    else {
      $row[] = '';
    }
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[][] = array(
      'data' => t("This order's products have not been organized into packages."),
      'colspan' => 10,
    );
  }
  $output = theme('table', $header, $rows);
  $result = db_query("SELECT op.order_product_id, CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) AS total, SUM(pp.qty) AS packaged FROM {uc_order_products} AS op LEFT JOIN {uc_packaged_products} AS pp ON op.order_product_id = pp.order_product_id WHERE op.order_id = %d AND op.data LIKE '%%%s%%' GROUP BY op.order_product_id HAVING SUM(pp.qty) IS NULL OR CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) > SUM(pp.qty)", $order_id, 's:9:"shippable";s:1:"1";');
  if (db_num_rows($result)) {
    $output .= l(t('Create packages.'), 'admin/store/orders/' . $order_id . '/packages/new');
  }
  return $output;
}