You are here

function commerce_fedex_create_rate_request in Commerce FedEx 7

Function to create FedEx rate request array.

Parameters

object $order: The order object.

Return value

array The array that is created for getting rates from FedEx.

1 call to commerce_fedex_create_rate_request()
commerce_fedex_service_rate_order in ./commerce_fedex.module
Returns an array of shipping method rates obtained from FedEx servers.

File

includes/commerce_fedex_soap_client.inc, line 17
Handles the SOAP request/response to FedEx Web Services servers.

Code

function commerce_fedex_create_rate_request($order) {
  $request = array();
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $request['TransactionDetail'] = array(
    'CustomerTransactionId' => ' *** Rate Request v13 using Drupal Commerce ***',
  );
  $request['Version'] = array(
    'ServiceId' => 'crs',
    'Major' => '13',
    'Intermediate' => '0',
    'Minor' => '0',
  );

  // Load the number of packages and their physical attributes.
  $package_line_items = _commerce_fedex_get_package_items($order, $order_wrapper);

  // Make sure that there are packages to be sent in the request.
  if (!empty($package_line_items)) {
    $request['ReturnTransitAndCommit'] = TRUE;
    $request['RequestedShipment']['DropoffType'] = variable_get('commerce_fedex_dropoff', 'REGULAR_PICKUP');
    $request['RequestedShipment']['ShipTimestamp'] = date('c');
    $request['RequestedShipment']['PackagingType'] = variable_get('commerce_fedex_default_package_type', 'YOUR_PACKAGING');
    $request['RequestedShipment']['Shipper'] = _commerce_fedex_get_shipper();
    $request['RequestedShipment']['Recipient'] = _commerce_fedex_get_recipient($order, $order_wrapper);
    $request['RequestedShipment']['RateRequestTypes'] = strtoupper(variable_get('commerce_fedex_rate_service_type', 'list'));
    $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
    $request['RequestedShipment']['PackageCount'] = count($package_line_items);
    $request['RequestedShipment']['RequestedPackageLineItems'] = $package_line_items;
    $request['RequestedShipment']['SmartPostDetail']['Indicia'] = variable_get('commerce_fedex_smartpost_indicia_type');
    $request['RequestedShipment']['SmartPostDetail']['HubID'] = variable_get('commerce_fedex_smartpost_hub_id');

    // Allow other modules to alter the rate request.
    drupal_alter('commerce_fedex_rate_request', $request, $order);

    // Return the request.
    if (!empty($request['RequestedShipment'])) {
      return $request;
    }
  }
  return FALSE;
}