function uc_shipping_new_shipment in Ubercart 7.3
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_new_shipment()
- 6.2 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_new_shipment()
Sets up a new shipment with the chosen packages.
See also
uc_shipping_new_shipment_submit()
theme_uc_shipping_new_shipment()
1 string reference to 'uc_shipping_new_shipment'
- uc_shipping_menu in shipping/
uc_shipping/ uc_shipping.module - Implements hook_menu().
File
- shipping/
uc_shipping/ uc_shipping.admin.inc, line 551 - Shipping administration menu items.
Code
function uc_shipping_new_shipment($form, &$form_state, $order) {
$checked_pkgs = isset($_GET['pkgs']) ? $_GET['pkgs'] : array();
$form['#tree'] = TRUE;
$form['order_id'] = array(
'#type' => 'hidden',
'#value' => $order->order_id,
);
$packages_by_type = array();
$units = variable_get('uc_weight_unit', 'lb');
$result = db_query("SELECT * FROM {uc_packages} WHERE order_id = :id AND sid IS NULL", array(
':id' => $order->order_id,
));
foreach ($result as $package) {
$products = array();
$weight = 0;
$result2 = db_query("SELECT pp.order_product_id, pp.qty, pp.qty * op.weight AS weight, op.weight_units, 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) {
$units_conversion = uc_weight_conversion($product->weight_units, $units);
$weight += $product->weight * $units_conversion;
$products[$product->order_product_id] = $product;
}
$package->weight = $weight;
$package->products = $products;
$packages_by_type[$package->shipping_type][$package->package_id] = $package;
}
$option_methods = array();
$shipping_types = uc_quote_get_shipping_types();
$shipping_methods = module_invoke_all('uc_shipping_method');
$shipping_methods_by_type = array();
foreach ($shipping_methods as $method) {
if (isset($method['ship'])) {
$shipping_methods_by_type[$method['ship']['type']][] = $method;
}
}
$pkgs_exist = FALSE;
foreach ($packages_by_type as $shipping_type => $packages) {
$form['shipping_types'][$shipping_type] = array(
'#type' => 'fieldset',
'#title' => $shipping_types[$shipping_type]['title'],
);
$form['shipping_types'][$shipping_type]['packages'] = array();
foreach ($packages as $package) {
$pkgs_exist = TRUE;
$package_row = array();
$package_row['checked'] = array(
'#type' => 'checkbox',
'#default_value' => in_array($package->package_id, $checked_pkgs) ? 1 : 0,
);
$package_row['package_id'] = array(
'#markup' => $package->package_id,
);
$product_list = array();
foreach ($package->products as $product) {
$product_list[] = $product->qty . ' x ' . check_plain($product->model);
}
$package_row['products'] = array(
'#markup' => '<ul><li>' . implode('</li><li>', $product_list) . '</li></ul>',
);
$package_row['weight'] = array(
'#markup' => uc_weight_format($package->weight, $units),
);
$form['shipping_types'][$shipping_type]['packages'][$package->package_id] = $package_row;
}
if (isset($shipping_methods_by_type[$shipping_type])) {
foreach ($shipping_methods_by_type[$shipping_type] as $method) {
$option_methods += array(
$method['id'] => $method['title'],
);
}
}
}
if ($pkgs_exist) {
$option_methods = array(
'all' => t('Ship Manually'),
) + $option_methods;
$form['method'] = array(
'#type' => 'select',
'#title' => t('Shipping method'),
'#options' => $option_methods,
'#default_value' => 'all',
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['ship'] = array(
'#type' => 'submit',
'#value' => t('Ship packages'),
);
}
return $form;
}