function uc_shipping_new_package in Ubercart 6.2
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_new_package()
- 7.3 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_new_package()
Puts ordered products into a package.
See also
uc_shipping_new_package_validate()
uc_shipping_new_package_submit()
theme_uc_shipping_new_package_fieldset()
1 string reference to 'uc_shipping_new_package'
- uc_shipping_menu in shipping/
uc_shipping/ uc_shipping.module - Implements hook_shipping_menu().
File
- shipping/
uc_shipping/ uc_shipping.admin.inc, line 65 - Shipping administration menu items.
Code
function uc_shipping_new_package($form_state, $order) {
$breadcrumb = drupal_get_breadcrumb();
$breadcrumb[] = l(t('Administer'), 'admin');
$breadcrumb[] = l(t('Store administration'), 'admin/store');
$breadcrumb[] = l(t('Orders'), 'admin/store/orders');
$breadcrumb[] = l(t('Order @id', array(
'@id' => $order->order_id,
)), 'admin/store/orders/' . $order->order_id);
$breadcrumb[] = l(t('Packages'), 'admin/store/orders/' . $order->order_id . '/packages');
drupal_set_breadcrumb($breadcrumb);
$form = array(
'#tree' => TRUE,
);
$form['instructions'] = array(
'#value' => t('Organize products into packages.
Package numbers in multiple shipping types are of the first shipping type they appear in. All
packages are given a unique ID when they are saved. Choose the default package "Sep." to
automatically create a package for each of the selected quantity of products in that row.'),
);
$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;
}
}
$shipping_type_weights = variable_get('uc_quote_type_weight', array());
$packaged_products = array();
$result = db_query("SELECT op.order_product_id, SUM(pp.qty) AS quantity FROM {uc_packaged_products} AS pp LEFT JOIN {uc_packages} AS p ON pp.package_id = p.package_id LEFT JOIN {uc_order_products} AS op ON op.order_product_id = pp.order_product_id WHERE p.order_id = %d GROUP BY op.order_product_id", $order->order_id);
while ($boxed_product = db_fetch_object($result)) {
$packaged_products[$boxed_product->order_product_id] = $boxed_product->quantity;
}
$form['shipping_types'] = array();
$shipping_type_options = uc_quote_shipping_type_options();
foreach ($shipping_types_products as $shipping_type => $products) {
$form['shipping_types'][$shipping_type] = array(
'#type' => 'fieldset',
'#title' => isset($shipping_type_options[$shipping_type]) ? $shipping_type_options[$shipping_type] : ucwords(str_replace('_', ' ', $shipping_type)),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => isset($shipping_type_weights[$shipping_type]) ? $shipping_type_weights[$shipping_type] : 0,
);
foreach ($products as $product) {
$unboxed_qty = $product->qty;
if (isset($packaged_products[$product->order_product_id])) {
$unboxed_qty -= $packaged_products[$product->order_product_id];
}
if ($unboxed_qty > 0) {
$product_row = array();
$product_row['checked'] = array(
'#type' => 'checkbox',
'#default_value' => 0,
);
$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, $unboxed_qty)),
'#default_value' => $unboxed_qty,
);
$options = drupal_map_assoc(uc_range(0, count($order->products)));
$options[0] = t('Sep.');
$product_row['package'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => 0,
);
$form['shipping_types'][$shipping_type][$product->order_product_id] = $product_row;
}
}
$form['shipping_types'][$shipping_type]['#theme'] = 'uc_shipping_new_package_fieldset';
}
$form['order_id'] = array(
'#type' => 'hidden',
'#value' => $order->order_id,
);
$form['create'] = array(
'#type' => 'submit',
'#value' => t('Make packages'),
);
$form['combine'] = array(
'#type' => 'submit',
'#value' => t('Create one package'),
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
);
return $form;
}