You are here

function _commerce_fedex_get_recipient in Commerce FedEx 7

Internal function to build recipient (ship to) array.

Parameters

object $order: The order object.

object $order_wrapper: The order entity wrapper.

Return value

array An array that represents the ship to address.

1 call to _commerce_fedex_get_recipient()
commerce_fedex_create_rate_request in includes/commerce_fedex_soap_client.inc
Function to create FedEx rate request array.

File

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

Code

function _commerce_fedex_get_recipient($order, $order_wrapper) {
  $field_name = commerce_physical_order_shipping_field_name($order);

  // Prepare the shipping address for use in the request.
  if (!empty($order_wrapper->{$field_name}->commerce_customer_address)) {
    $shipping_address = $order_wrapper->{$field_name}->commerce_customer_address
      ->value();
  }
  else {
    $field = field_info_field('commerce_customer_address');
    $instance = field_info_instance('commerce_customer_profile', $field['field_name'], 'shipping');
    $shipping_address = addressfield_default_values($field, $instance);
  }
  $recipient = array(
    'Contact' => array(
      'PersonName' => $shipping_address['name_line'],
    ),
    'Address' => array(
      'StreetLines' => array(
        $shipping_address['thoroughfare'],
      ),
      'City' => $shipping_address['locality'],
      'PostalCode' => $shipping_address['postal_code'],
      'CountryCode' => $shipping_address['country'],
      'Residential' => variable_get('commerce_fedex_shipto_residential', 'residential') == 'residential' ? TRUE : FALSE,
    ),
  );

  // StateOrProvinceCode is only required for shipping to U.S. and Canada.
  if (in_array($shipping_address['country'], array(
    'US',
    'CA',
  ))) {
    $recipient['Address']['StateOrProvinceCode'] = $shipping_address['administrative_area'];
  }
  return $recipient;
}