function uc_ups_fulfill_order in Ubercart 6.2
Same name and namespace in other branches
- 8.4 shipping/uc_ups/src/Plugin/Ubercart/FulfillmentMethod/uc_ups.ship.inc \uc_ups_fulfill_order()
- 5 shipping/uc_ups/uc_ups.module \uc_ups_fulfill_order()
- 7.3 shipping/uc_ups/uc_ups.ship.inc \uc_ups_fulfill_order()
Shipment creation callback.
Confirms 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_validate()
2 string references to 'uc_ups_fulfill_order'
- hook_shipping_method in docs/
hooks.php - Defines callbacks and service options for shipping methods.
- uc_ups_shipping_method in shipping/
uc_ups/ uc_ups.module - Implements hook_shipping_method().
File
- shipping/
uc_ups/ uc_ups.ship.inc, line 23 - UPS functions for label generation.
Code
function uc_ups_fulfill_order($form_state, $order, $package_ids) {
$form = array();
$pkg_types = _uc_ups_pkg_types();
$form['order_id'] = array(
'#type' => 'value',
'#value' => $order->order_id,
);
$packages = array();
$addresses = array();
// Container for package data
$form['packages'] = array(
'#type' => 'fieldset',
'#title' => t('Packages'),
'#collapsible' => TRUE,
'#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 (last one in
// the loop) to use for some 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;
}
// Use last product in package to determine package type
$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_form['weight'] = array(
'#type' => 'fieldset',
'#title' => t('Weight'),
'#description' => t('Weight of the package. Default value is sum of product weights in the package.'),
'#weight' => 15,
'#theme' => 'uc_shipping_package_dimensions',
);
$pkg_form['weight']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => isset($package->weight) ? $package->weight : 0,
'#size' => 10,
'#maxlength' => 15,
);
$pkg_form['weight']['units'] = array(
'#type' => 'select',
'#title' => t('Units'),
'#options' => array(
'lb' => t('Pounds'),
'kg' => t('Kilograms'),
'oz' => t('Ounces'),
'g' => t('Grams'),
),
'#default_value' => isset($package->weight_units) ? $package->weight_units : variable_get('uc_weight_unit', 'lb'),
);
$pkg_form['dimensions'] = array(
'#type' => 'fieldset',
'#title' => t('Dimensions'),
'#description' => t('Physical dimensions of the package.'),
'#weight' => 20,
'#theme' => 'uc_shipping_package_dimensions',
);
$pkg_form['dimensions']['length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => isset($product->length) ? $product->length : 1,
'#size' => 8,
);
$pkg_form['dimensions']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => isset($product->width) ? $product->width : 1,
'#size' => 8,
);
$pkg_form['dimensions']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => isset($product->height) ? $product->height : 1,
'#size' => 8,
);
$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' => isset($product->length_units) ? $product->length_units : variable_get('uc_length_unit', 'in'),
);
$form['packages'][$id] = $pkg_form;
}
}
$form = array_merge($form, uc_shipping_address_form($form_state, $addresses, $order));
foreach (array(
'delivery_email',
'delivery_last_name',
'delivery_street1',
'delivery_city',
'delivery_country',
'delivery_postal_code',
) as $field) {
$form['destination'][$field]['#required'] = TRUE;
}
// Determine shipping option chosen by the customer
$method = $order->quote['method'];
$methods = module_invoke_all('shipping_method');
if (isset($methods[$method])) {
$services = $methods[$method]['quote']['accessorials'];
$method = $services[$order->quote['accessorials']];
}
// Container for shipment data
$form['shipment'] = array(
'#type' => 'fieldset',
'#title' => t('Shipment data'),
'#collapsible' => TRUE,
);
// Inform user of customer's shipping choice
$form['shipment']['shipping_choice'] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#value' => t('Customer selected "@method" as the shipping method and paid @rate', array(
'@method' => $method,
'@rate' => uc_currency_format($order->quote['rate']),
)),
'#suffix' => '</div>',
);
// Pass shipping charge paid information on to validation function so it
// can be displayed alongside actual costs
$form['shipment']['paid'] = array(
'#type' => 'value',
'#value' => uc_currency_format($order->quote['rate']),
);
$services = _uc_ups_service_list();
$default_service = '';
if ($method == 'ups') {
$default_service = $order->quote['accessorials'];
}
$form['shipment']['service'] = array(
'#type' => 'select',
'#title' => t('UPS service'),
'#options' => $services,
'#default_value' => $default_service,
);
$today = getdate();
$form['shipment']['ship_date'] = array(
'#type' => 'date',
'#title' => t('Ship date'),
'#default_value' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
);
$form['shipment']['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'),
);
return $form;
}