function uc_ups_fulfill_order in Ubercart 5
Same name and namespace in other branches
- 8.4 shipping/uc_ups/src/Plugin/Ubercart/FulfillmentMethod/uc_ups.ship.inc \uc_ups_fulfill_order()
- 6.2 shipping/uc_ups/uc_ups.ship.inc \uc_ups_fulfill_order()
- 7.3 shipping/uc_ups/uc_ups.ship.inc \uc_ups_fulfill_order()
Shipment creation callback.
Confirm shipment data before requesting a shipping label.
Parameters
$order_id: The order id for the shipment.
$package_ids: Array of package ids to shipped.
See also
uc_ups_fulfill_order_submit
2 string references to 'uc_ups_fulfill_order'
- hook_shipping_method in docs/
hooks.php - Define callbacks and service options for shipping methods.
- uc_ups_shipping_method in shipping/
uc_ups/ uc_ups.module - Implementation of Übercart's hook_shipping_method().
File
- shipping/
uc_ups/ uc_ups.module, line 998 - Shipping quote module that interfaces with www.ups.com to get rates for small package shipments.
Code
function uc_ups_fulfill_order($order_id, $package_ids) {
$form = array();
$pkg_types = _uc_ups_pkg_types();
if ($order = uc_order_load($order_id)) {
$form['order_id'] = array(
'#type' => 'value',
'#value' => $order_id,
);
$packages = array();
$addresses = array();
$form['packages'] = array(
'#tree' => true,
);
foreach ($package_ids as $id) {
$package = uc_shipping_package_load($id);
if ($package) {
foreach ($package->addresses as $address) {
if (!in_array($address, $addresses)) {
$addresses[] = $address;
}
}
// Create list of products and get a representative product for default values
$product_list = array();
$declared_value = 0;
foreach ($package->products as $product) {
$product_list[] = $product->qty . ' x ' . $product->model;
$declared_value += $product->qty * $product->price;
}
$ups_data = db_fetch_array(db_query("SELECT pkg_type FROM {uc_ups_products} WHERE nid = %d", $product->nid));
$product->ups = $ups_data;
$pkg_form = array(
'#type' => 'fieldset',
'#title' => t('Package !id', array(
'!id' => $id,
)),
);
$pkg_form['products'] = array(
'#value' => theme('item_list', $product_list),
);
$pkg_form['package_id'] = array(
'#type' => 'hidden',
'#value' => $id,
);
$pkg_form['pkg_type'] = array(
'#type' => 'select',
'#title' => t('Package type'),
'#options' => $pkg_types,
'#default_value' => $product->ups['pkg_type'],
'#required' => true,
);
$pkg_form['declared_value'] = array(
'#type' => 'textfield',
'#title' => t('Declared value'),
'#default_value' => $declared_value,
'#required' => true,
);
$pkg_type['dimensions'] = array(
'#type' => 'fieldset',
'#title' => t('Dimensions'),
'#description' => t('Physical dimensions of the package.'),
'#theme' => 'uc_ups_dimensions',
);
$pkg_form['dimensions']['units'] = array(
'#type' => 'select',
'#title' => t('Units of measurement'),
'#options' => array(
'in' => t('Inches'),
'ft' => t('Feet'),
'cm' => t('Centimeters'),
'mm' => t('Millimeters'),
),
'#default_value' => $product->length_units ? $product->length_units : variable_get('uc_length_unit', 'in'),
);
$pkg_form['dimensions']['length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => $product->length,
);
$pkg_form['dimensions']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $product->width,
);
$pkg_form['dimensions']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $product->height,
);
$form['packages'][$id] = $pkg_form;
}
}
$form = array_merge($form, uc_shipping_address_form($addresses, $order));
foreach (array(
'delivery_email',
'delivery_last_name',
'delivery_company',
'delivery_street1',
'delivery_city',
'delivery_zone',
'delivery_country',
'delivery_postal_code',
) as $field) {
$form['destination'][$field]['#required'] = true;
}
$ups_services = _uc_ups_service_list();
$services = array_filter(variable_get('uc_ups_services', array()));
foreach ($services as $ups_id => $service) {
$services[$ups_id] = $ups_services[$ups_id];
}
if (count($services)) {
$form['service'] = array(
'#type' => 'select',
'#title' => t('UPS service'),
'#options' => $services,
);
}
$today = getdate();
$form['ship_date'] = array(
'#type' => 'date',
'#title' => t('Ship date'),
'#default_value' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
);
$form['expected_delivery'] = array(
'#type' => 'date',
'#title' => t('Expected delivery'),
'#default_value' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Review shipment'),
);
}
else {
drupal_set_message(t("What? That's not an order id. You can't create a shipment without an order."));
drupal_goto('admin/store/orders');
}
return $form;
}