You are here

function uc_shipping_shipment_save in Ubercart 6.2

Same name and namespace in other branches
  1. 5 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.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.
1 string reference to 'uc_shipping_shipment_save'
uc_shipping_ca_entity in shipping/uc_shipping/uc_shipping.ca.inc
@file Conditional actions hooks for uc_shipping.module.

File

shipping/uc_shipping/uc_shipping.module, line 528

Code

function uc_shipping_shipment_save($shipment) {
  if (!isset($shipment->sid)) {
    db_query("INSERT INTO {uc_shipments} (order_id) VALUES (%d)", $shipment->order_id);
    $shipment->sid = db_last_insert_id('uc_shipments', 'sid');
    $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, changed = %d 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, time(), $shipment->sid);
  module_invoke_all('shipment', 'save', $shipment);
  $order = uc_order_load($shipment->order_id);
  ca_pull_trigger('uc_shipment_save', $order, $shipment);
}