function uc_shipping_shipment_save in Ubercart 7.3
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_shipment_save()
- 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_shipment_save()
Saves a shipment.
2 calls to uc_shipping_shipment_save()
- uc_shipping_shipment_edit_submit in shipping/
uc_shipping/ uc_shipping.admin.inc - Submit handler for uc_shipping_shipment_edit().
- uc_ups_confirm_shipment_submit in shipping/
uc_ups/ uc_ups.ship.inc - Generates label and schedules pickup of the shipment.
File
- shipping/
uc_shipping/ uc_shipping.module, line 566 - 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_shipment_save($shipment) {
if (isset($shipment->origin)) {
foreach ($shipment->origin as $field => $value) {
$field = 'o_' . $field;
$shipment->{$field} = $value;
$fields[$field] = $value;
}
}
if (isset($shipment->destination)) {
foreach ($shipment->destination as $field => $value) {
$field = 'd_' . $field;
$shipment->{$field} = $value;
$fields[$field] = $value;
}
}
$shipment->changed = time();
if (!isset($shipment->sid)) {
drupal_write_record('uc_shipments', $shipment);
$shipment->is_new = TRUE;
}
else {
drupal_write_record('uc_shipments', $shipment, 'sid');
$shipment->is_new = FALSE;
}
if (is_array($shipment->packages)) {
foreach ($shipment->packages as $package) {
$package->sid = $shipment->sid;
// Since the products haven't changed, we take them out of the object so
// that they are not deleted and re-inserted.
$products = $package->products;
unset($package->products);
uc_shipping_package_save($package);
// But they're still necessary for hook_uc_shipment(), so they're added
// back in.
$package->products = $products;
}
}
module_invoke_all('uc_shipment', 'save', $shipment);
$order = uc_order_load($shipment->order_id);
rules_invoke_event('uc_shipment_save', $order, $shipment);
}