function uc_shipping_order_packages in Ubercart 6.2
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_order_packages()
- 7.3 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_shipping_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 = %d", $order->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[] = 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->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->order_id . '/shipments/labels/' . $method . '/' . $package->label_image, array(
'html' => TRUE,
)) : '';
$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' => 'pkgs[]=' . $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');
}
$output = theme('table', $header, $rows);
$result = db_query("SELECT op.order_product_id, CASE WHEN COUNT(pp.qty) = 0 THEN 0 ELSE SUM(op.qty) / COUNT(pp.qty) END 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 CASE WHEN COUNT(pp.qty) = 0 THEN 0 ELSE SUM(op.qty) / COUNT(pp.qty) END > SUM(pp.qty)", $order->order_id, 's:9:"shippable";s:1:"1";');
if (db_fetch_object($result)) {
$output .= l(t('Create packages.'), 'admin/store/orders/' . $order->order_id . '/packages/new');
}
return $output;
}