function uc_shipping_new_package_submit in Ubercart 6.2
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_new_package_submit()
- 7.3 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_new_package_submit()
Submit handler for uc_shipping_new_package().
See also
uc_shipping_new_package_validate()
File
- shipping/
uc_shipping/ uc_shipping.admin.inc, line 197 - Shipping administration menu items.
Code
function uc_shipping_new_package_submit($form, &$form_state) {
if ($form_state['values']['op'] != t('Cancel')) {
$packages = array(
0 => array(),
);
foreach ($form_state['values']['shipping_types'] as $shipping_type => $products) {
foreach ($products as $id => $product) {
if ($product['checked']) {
if ($form_state['values']['op'] == t('Create one package')) {
$product['package'] = 1;
}
if ($product['package'] != 0) {
$packages[$product['package']]['products'][$id] = (object) $product;
if (!isset($packages[$product['package']]['shipping_type'])) {
$packages[$product['package']]['shipping_type'] = $shipping_type;
}
}
else {
$packages[0][$shipping_type][$id] = (object) $product;
}
}
}
if (isset($packages[0][$shipping_type])) {
foreach ($packages[0][$shipping_type] as $id => $product) {
$qty = $product->qty;
$product->qty = 1;
for ($i = 0; $i < $qty; $i++) {
$packages[] = array(
'products' => array(
$id => $product,
),
'shipping_type' => $shipping_type,
);
}
}
}
unset($packages[0][$shipping_type]);
}
if (empty($packages[0])) {
unset($packages[0]);
}
foreach ($packages as $package) {
$package['order_id'] = $form_state['values']['order_id'];
uc_shipping_package_save($package);
}
}
$form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/packages';
}