You are here

function uc_shipping_shipment_edit_submit in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_shipment_edit_submit()
  2. 7.3 shipping/uc_shipping/uc_shipping.admin.inc \uc_shipping_shipment_edit_submit()

Submit handler for uc_shipping_shipment_edit().

File

shipping/uc_shipping/uc_shipping.module, line 1046
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_edit_submit($form_id, $form_values) {
  if ($form_values['op'] != t('Cancel')) {
    $shipment = new stdClass();
    $shipment->order_id = $form_values['order_id'];
    if (isset($form_values['sid'])) {
      $shipment->sid = $form_values['sid'];
    }
    $shipment->origin = new stdClass();
    $shipment->destination = new stdClass();
    foreach ($form_values as $key => $value) {
      if (substr($key, 0, 7) == 'pickup_') {
        $field = substr($key, 7);
        $shipment->origin->{$field} = $value;
      }
      else {
        if (substr($key, 0, 9) == 'delivery_') {
          $field = substr($key, 9);
          $shipment->destination->{$field} = $value;
        }
      }
    }
    $shipment->packages = array();
    foreach ($form_values['packages'] as $id => $pkg_form) {
      $package = uc_shipping_package_load($id);
      $package->pkg_type = $pkg_form['pkg_type'];
      $package->value = $pkg_form['declared_value'];
      $package->length = $pkg_form['dimensions']['length'];
      $package->width = $pkg_form['dimensions']['width'];
      $package->height = $pkg_form['dimensions']['height'];
      $package->length_units = $pkg_form['dimensions']['units'];
      $package->tracking_number = $pkg_form['tracking_number'];
      $package->qty = 1;
      $shipment->packages[$id] = $package;
    }
    $shipment->shipping_method = $form_values['shipping_method'];
    $shipment->accessorials = $form_values['accessorials'];
    $shipment->carrier = $form_values['carrier'];
    $shipment->transaction_id = $form_values['transaction_id'];
    $shipment->tracking_number = $form_values['tracking_number'];
    $shipment->ship_date = gmmktime(12, 0, 0, $form_values['ship_date']['month'], $form_values['ship_date']['day'], $form_values['ship_date']['year']);
    $shipment->expected_delivery = gmmktime(12, 0, 0, $form_values['expected_delivery']['month'], $form_values['expected_delivery']['day'], $form_values['expected_delivery']['year']);
    $shipment->cost = $form_values['cost'];
    uc_shipping_shipment_save($shipment);
  }
  return 'admin/store/orders/' . $form_values['order_id'] . '/shipments';
}