function uc_fedex_fulfill_order in FedEx Shipping 6.2
Same name and namespace in other branches
- 7.2 uc_fedex.ship.inc \uc_fedex_fulfill_order()
Shipment creation callback.
Confirms shipment data before requesting a shipping label.
Parameters
$order: The order object for the shipment.
$package_ids: Array of package ids to shipped.
See also
uc_fedex_fulfill_order_validate()
uc_fedex_fulfill_order_submit()
2 string references to 'uc_fedex_fulfill_order'
- uc_fedex_fulfill_order_validate in ./
uc_fedex.ship.inc - Passes final information into shipment object.
- uc_fedex_shipping_method in ./
uc_fedex.module - Implements Ubercart's hook_shipping_method().
File
- ./
uc_fedex.ship.inc, line 496 - FedEx Web Services Rate / Available Services Quote.
Code
function uc_fedex_fulfill_order($form_state, $order, $package_ids) {
$form = array();
$pkg_types = _uc_fedex_package_types();
$form['order_id'] = array(
'#type' => 'value',
'#value' => $order->order_id,
);
$packages = array();
$addresses = array();
// Container for package data
$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;
}
$fedex_data = db_fetch_array(db_query("SELECT pkg_type FROM {uc_fedex_products} WHERE nid = %d", $product->nid));
$package->fedex = $fedex_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' => $package->fedex['pkg_type'],
'#required' => TRUE,
);
$pkg_form['declared_value'] = array(
'#type' => 'textfield',
'#title' => t('Declared value'),
'#default_value' => $declared_value,
'#required' => TRUE,
);
$pkg_type['weight'] = array(
'#type' => 'fieldset',
'#title' => t('Weight'),
'#description' => t('Weight of the package. Default value is sum of product weights in the package.'),
'#theme' => 'uc_shipping_package_dimensions',
);
$pkg_form['weight']['units'] = array(
'#type' => 'select',
'#title' => t('Weight 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['weight']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => isset($package->weight) ? $package->weight : 0,
);
$pkg_type['dimensions'] = array(
'#type' => 'fieldset',
'#title' => t('Dimensions'),
'#description' => t('Physical dimensions of the package.'),
'#theme' => 'uc_shipping_package_dimensions',
);
$pkg_form['dimensions']['units'] = array(
'#type' => 'select',
'#title' => t('Length units'),
'#options' => array(
'in' => t('Inches'),
'ft' => t('Feet'),
'cm' => t('Centimeters'),
'mm' => t('Millimeters'),
),
'#default_value' => isset($package->length_units) ? $package->length_units : variable_get('uc_length_unit', 'in'),
);
$pkg_form['dimensions']['length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => isset($package->length) ? $package->length : 1,
);
$pkg_form['dimensions']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => isset($package->width) ? $package->width : 1,
);
$pkg_form['dimensions']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => isset($package->height) ? $package->height : 1,
);
$form['packages'][$id] = $pkg_form;
}
}
$form = array_merge($form, uc_shipping_address_form($form_state, $addresses, $order));
// Mark fields needed by the FedEx API as 'required'
foreach (array(
'delivery_email',
'delivery_last_name',
'delivery_phone',
'delivery_street1',
'delivery_city',
'delivery_zone',
'delivery_country',
'delivery_postal_code',
) as $field) {
$form['destination'][$field]['#required'] = TRUE;
}
// Allow selection of address type
$form['destination']['delivery_residential'] = array(
'#type' => 'radios',
'#title' => t('Address type'),
'#default_value' => variable_get('uc_fedex_residential_quotes', TRUE),
'#options' => array(
0 => t('Commercial'),
1 => t('Residential'),
),
'#required' => TRUE,
);
// Determine shipping option chosen by the customer
$methods = module_invoke_all('shipping_method');
$services = $methods[$order->quote['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 = array_merge(_uc_fedex_ground_services(), _uc_fedex_express_services(), _uc_fedex_freight_services());
$default_service = '';
$method = $order->quote['method'];
if ($method == 'fedex_ground' || $method == 'fedex' || $method == 'fedex_freight') {
$default_service = $order->quote['accessorials'];
}
$form['shipment']['service'] = array(
'#type' => 'select',
'#title' => t('FedEx 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']['reference'] = array(
'#type' => 'textfield',
'#title' => t('Reference Number'),
'#maxlength' => 40,
// FedEx limit
'#default_value' => '',
'#required' => FALSE,
'#description' => t('Optional information to include on shipping label. Limited to 40 characters.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Review shipment'),
);
return $form;
}