You are here

function uc_shipping_shipment_edit_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 5 shipping/uc_shipping/uc_shipping.module \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().

See also

uc_shipping_shipment_edit()

uc_shipping_shipment_validate()

File

shipping/uc_shipping/uc_shipping.admin.inc, line 943
Shipping administration menu items.

Code

function uc_shipping_shipment_edit_submit($form, &$form_state) {
  $shipment = new stdClass();
  $shipment->order_id = $form_state['values']['order_id'];
  if (isset($form_state['values']['sid'])) {
    $shipment->sid = $form_state['values']['sid'];
  }
  $shipment->origin = new stdClass();
  $shipment->destination = new stdClass();
  foreach ($form_state['values'] as $key => $value) {
    if (substr($key, 0, 7) == 'pickup_') {
      $field = substr($key, 7);
      $shipment->origin->{$field} = $value;
    }
    elseif (substr($key, 0, 9) == 'delivery_') {
      $field = substr($key, 9);
      $shipment->destination->{$field} = $value;
    }
  }
  $shipment->packages = array();
  foreach ($form_state['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_state['values']['shipping_method'];
  $shipment->accessorials = $form_state['values']['accessorials'];
  $shipment->carrier = $form_state['values']['carrier'];
  $shipment->transaction_id = $form_state['values']['transaction_id'];
  $shipment->tracking_number = $form_state['values']['tracking_number'];
  $shipment->ship_date = gmmktime(12, 0, 0, $form_state['values']['ship_date']['month'], $form_state['values']['ship_date']['day'], $form_state['values']['ship_date']['year']);
  $shipment->expected_delivery = gmmktime(12, 0, 0, $form_state['values']['expected_delivery']['month'], $form_state['values']['expected_delivery']['day'], $form_state['values']['expected_delivery']['year']);
  $shipment->cost = $form_state['values']['cost'];
  uc_shipping_shipment_save($shipment);
  $form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/shipments';
}