function uc_shipping_package_edit in Ubercart 5
Same name and namespace in other branches
- 6.2 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_package_edit()
- 7.3 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_package_edit()
Rearrange the products in or out of a package.
See also
theme_uc_shipping_edit_package_fieldset
uc_shipping_package_edit_submit
1 string reference to 'uc_shipping_package_edit'
- uc_shipping_menu in shipping/
uc_shipping/ uc_shipping.module - Implementation of hook_shipping_menu().
File
- shipping/
uc_shipping/ uc_shipping.module, line 432 - 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_package_edit($order_id, $package_id) {
$package = uc_shipping_package_load($package_id);
$products = array();
$order = uc_order_load($order_id);
$shipping_types_products = array();
foreach ($order->products as $product) {
if ($product->data['shippable']) {
$product->shipping_type = uc_product_get_shipping_type($product);
$shipping_types_products[$product->shipping_type][$product->order_product_id] = $product;
$products[$product->order_product_id] = $product;
}
}
$result = db_query("SELECT order_product_id, SUM(qty) AS quantity FROM {uc_packaged_products} AS pp LEFT JOIN {uc_packages} AS p ON pp.package_id = p.package_id WHERE p.order_id = %d GROUP BY order_product_id", $order_id);
while ($packaged_product = db_fetch_object($result)) {
//Make already packaged products unavailable, except those in this package.
$products[$packaged_product->order_product_id]->qty = $products[$packaged_product->order_product_id]->qty - $packaged_product->quantity + $package->products[$packaged_product->order_product_id]->qty;
}
$form = array();
$form['#tree'] = true;
$form['package_id'] = array(
'#type' => 'hidden',
'#value' => $package_id,
);
$form['products'] = array();
foreach ($products as $product) {
if ($product->qty > 0) {
$product_row = array();
$product_row['checked'] = array(
'#type' => 'checkbox',
'#default_value' => isset($package->products[$product->order_product_id]),
);
$product_row['model'] = array(
'#type' => 'markup',
'#value' => check_plain($product->model),
);
$product_row['name'] = array(
'#type' => 'markup',
'#value' => filter_xss_admin($product->title),
);
$product_row['qty'] = array(
'#type' => 'select',
'#options' => drupal_map_assoc(uc_range(1, $product->qty)),
'#default_value' => $package->products[$product->order_product_id]->qty,
);
$form['products'][$product->order_product_id] = $product_row;
}
}
$form['products']['#theme'] = 'uc_shipping_edit_package_fieldset';
$options = array();
foreach (array_keys($shipping_types_products) as $type) {
$options[$type] = ucwords(str_replace('_', ' ', $type));
}
$form['shipping_type'] = array(
'#type' => 'select',
'#title' => t('Shipping type'),
'#options' => $options,
'#default_value' => $package->shipping_type,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
);
return $form;
}