You are here

function _commerce_fedex_get_insurance_value in Commerce FedEx 7

Internal function to caluclate insurance value of shippable line items.

Parameters

object $order: The commerce order object for the order that we're requesting rates for.

Return value

array The total value of shippable items in the order for insurance.

1 call to _commerce_fedex_get_insurance_value()
_commerce_fedex_get_package_items in includes/commerce_fedex_soap_client.inc
Internal function to determine shippable line items from the order.

File

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

Code

function _commerce_fedex_get_insurance_value($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_total = $order_wrapper->commerce_order_total
    ->value();
  $insurance_value = 0;

  // Loop over each line item on the order.
  foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {

    // Only collect value of product line items that are shippable.
    if (in_array($line_item_wrapper->type
      ->value(), commerce_product_line_item_types()) && commerce_physical_line_item_shippable($line_item_wrapper
      ->value())) {
      $line_item_total = $line_item_wrapper->commerce_total
        ->value();

      // Increment the insurance value from the line items value.
      $insurance_value += commerce_currency_amount_to_decimal($line_item_total['amount'], $line_item_total['currency_code']);
    }
  }

  // Return the insurance value and currency code of shippable items.
  return array(
    'amount' => $insurance_value,
    'currency_code' => $order_total['currency_code'],
  );
}