You are here

function uc_shipping_order_packages in Ubercart 7.3

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

Displays 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
Implements hook_menu().

File

shipping/uc_shipping/uc_shipping.admin.inc, line 11
Shipping administration menu items.

Code

function uc_shipping_order_packages($order) {
  $shipping_type_options = uc_quote_shipping_type_options();
  $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' => 4,
    ),
  );
  $rows = array();
  $result = db_query("SELECT * FROM {uc_packages} WHERE order_id = :id", array(
    ':id' => $order->order_id,
  ));
  foreach ($result as $package) {
    $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} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id", array(
      ':id' => $package->package_id,
    ));
    foreach ($result2 as $product) {
      $product_list[] = $product->qty . ' x ' . check_plain($product->model);
    }
    $row[] = '<ul><li>' . implode('</li><li>', $product_list) . '</li></ul>';
    $row[] = isset($shipping_type_options[$package->shipping_type]) ? $shipping_type_options[$package->shipping_type] : strtr($package->shipping_type, '_', ' ');
    $row[] = check_plain($package->pkg_type);
    $row[] = isset($package->sid) ? l($package->sid, 'admin/store/orders/' . $order->order_id . '/shipments/' . $package->sid . '/view') : '';
    $row[] = isset($package->tracking_number) ? check_plain($package->tracking_number) : '';
    if ($package->label_image && ($image = file_load($package->label_image))) {
      $package->label_image = $image;
    }
    else {
      unset($package->label_image);
    }
    if (isset($package->sid) && isset($package->label_image)) {
      $method = db_query("SELECT shipping_method FROM {uc_shipments} WHERE sid = :sid", array(
        ':sid' => $package->sid,
      ))
        ->fetchField();
      $row[] = l(theme('image_style', array(
        'style_name' => 'uc_thumbnail',
        'path' => $package->label_image->uri,
        'alt' => t('Shipping label'),
        'title' => t('Shipping label'),
      )), 'admin/store/orders/' . $order->order_id . '/shipments/labels/' . $method . '/' . $package->label_image->uri, array(
        'html' => TRUE,
      ));
    }
    else {
      $row[] = '';
    }
    $row[] = l(t('edit'), 'admin/store/orders/' . $order->order_id . '/packages/' . $package->package_id . '/edit');
    $row[] = l(t('ship'), 'admin/store/orders/' . $order->order_id . '/shipments/new', array(
      'query' => array(
        'pkgs' => array(
          $package->package_id,
        ),
      ),
    ));
    $row[] = l(t('delete'), 'admin/store/orders/' . $order->order_id . '/packages/' . $package->package_id . '/delete');
    if ($package->sid) {
      $row[] = l(t('cancel shipment'), 'admin/store/orders/' . $order->order_id . '/packages/' . $package->package_id . '/cancel');
    }
    else {
      $row[] = '';
    }
    $rows[] = $row;
  }
  if (empty($rows)) {
    drupal_set_message(t("This order's products have not been organized into packages."));
    drupal_goto('admin/store/orders/' . $order->order_id . '/packages/new');
  }
  $build['packages'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}