You are here

function uc_shipping_shipment_save in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_shipment_save()
  2. 7.3 shipping/uc_shipping/uc_shipping.module \uc_shipping_shipment_save()

Save a shipment.

2 calls to uc_shipping_shipment_save()
uc_shipping_shipment_edit_submit in shipping/uc_shipping/uc_shipping.module
Submit handler for uc_shipping_shipment_edit().
uc_ups_confirm_shipment_submit in shipping/uc_ups/uc_ups.module
Submit handler for uc_ups_confirm_shipment().

File

shipping/uc_shipping/uc_shipping.module, line 1265
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 (!$shipment->sid) {
    $shipment->sid = db_next_id('{uc_shipments}_sid');
    db_query("INSERT INTO {uc_shipments} (sid, order_id) VALUES (%d, %d)", $shipment->sid, $shipment->order_id);
    $shipment->is_new = TRUE;
  }
  else {
    $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_shipment(), so they're added back in.
      $package->products = $products;
    }
  }
  if (isset($shipment->origin)) {
    foreach ($shipment->origin as $field => $value) {
      $field = 'o_' . $field;
      $shipment->{$field} = $value;
    }
  }
  if (isset($shipment->destination)) {
    foreach ($shipment->destination as $field => $value) {
      $field = 'd_' . $field;
      $shipment->{$field} = $value;
    }
  }
  db_query("UPDATE {uc_shipments} SET order_id = %d, o_first_name = '%s', o_last_name = '%s', o_company = '%s', o_street1 = '%s', o_street2 = '%s', o_city = '%s', o_zone = %d, o_postal_code = '%s', o_country = %d, d_first_name = '%s', d_last_name = '%s', d_company = '%s', d_street1 = '%s', d_street2 = '%s', d_city = '%s', d_zone = %d, d_postal_code = '%s', d_country = %d, shipping_method = '%s', accessorials = '%s', carrier = '%s', transaction_id = '%s', tracking_number = '%s', ship_date = %d, expected_delivery = %d, cost = %f WHERE sid = %d", $shipment->order_id, $shipment->o_first_name, $shipment->o_last_name, $shipment->o_company, $shipment->o_street1, $shipment->o_street2, $shipment->o_city, $shipment->o_zone, $shipment->o_postal_code, $shipment->o_country, $shipment->d_first_name, $shipment->d_last_name, $shipment->d_company, $shipment->d_street1, $shipment->d_street2, $shipment->d_city, $shipment->d_zone, $shipment->d_postal_code, $shipment->d_country, $shipment->shipping_method, $shipment->accessorials, $shipment->carrier, $shipment->transaction_id, $shipment->tracking_number, $shipment->ship_date, $shipment->expected_delivery, $shipment->cost, $shipment->sid);
  module_invoke_all('shipment', 'save', $shipment);
}