You are here

function commerce_shipping_service_rate_options in Commerce Shipping 7.2

Turns an array of shipping rates into a form element options array.

Parameters

object $order: An order object with a shipping_rates property defined as an array of shipping rate price arrays keyed by shipping service name.

Return value

array An options array of calculated shipping rates labeled using the display title of the shipping services.

2 calls to commerce_shipping_service_rate_options()
commerce_shipping_line_item_add_form in ./commerce_shipping.module
Helper function.
commerce_shipping_pane_checkout_form in includes/commerce_shipping.checkout_pane.inc
Checkout pane callback: builds a shipping quote selection form.

File

./commerce_shipping.module, line 650
Defines a system for calculating shipping costs associated with an order.

Code

function commerce_shipping_service_rate_options($order, &$form_state) {
  $options = array();
  foreach ($order->shipping_rates as $name => $line_item) {
    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
    $options[$name] = t('!shipping_service: !price', array(
      '!shipping_service' => commerce_shipping_line_item_title($line_item),
      '!price' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount
        ->value(), $line_item_wrapper->commerce_unit_price->currency_code
        ->value()),
    ));
  }

  // Allow modules to alter the options array generated for the rates.
  drupal_alter('commerce_shipping_service_rate_options', $options, $order, $form_state);
  return $options;
}