You are here

function commerce_shipping_services in Commerce Shipping 7.2

Returns an array of shipping services keyed by name.

Parameters

string $method: The machine-name of a shipping method to filter the return value by.

Return value

array Array of shipping services.

8 calls to commerce_shipping_services()
commerce_shipping_commerce_price_component_type_info in ./commerce_shipping.module
Implements hook_commerce_price_component_type_info().
commerce_shipping_default_rules_configuration in ./commerce_shipping.rules_defaults.inc
Implements hook_default_rules_configuration().
commerce_shipping_method_collect_rates in ./commerce_shipping.module
Collects available shipping services of the specified method for an order.
commerce_shipping_rules_action_info in ./commerce_shipping.rules.inc
Implements hook_rules_action_info().
commerce_shipping_service_get_title in ./commerce_shipping.module
Returns the human readable title of any or all shipping services.

... See full list

1 string reference to 'commerce_shipping_services'
commerce_shipping_services_reset in ./commerce_shipping.module
Resets the cached list of shipping services.

File

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

Code

function commerce_shipping_services($method = NULL) {

  // First check the static cache for a shipping services array.
  $shipping_services =& drupal_static(__FUNCTION__);

  // If it did not exist, fetch the services now.
  if (!isset($shipping_services)) {
    $shipping_services = array();

    // Find shipping services defined by hook_commerce_shipping_service_info().
    $weight = 0;
    foreach (module_implements('commerce_shipping_service_info') as $module) {
      foreach ((array) module_invoke($module, 'commerce_shipping_service_info') as $name => $shipping_service) {

        // Initialize shipping service properties if necessary.
        $defaults = array(
          'name' => $name,
          'base' => $name,
          'display_title' => $shipping_service['title'],
          'description' => '',
          'shipping_method' => '',
          'rules_component' => TRUE,
          'price_component' => $name,
          'weight' => $weight++,
          'callbacks' => array(),
          'module' => $module,
        );
        $shipping_service = array_merge($defaults, $shipping_service);

        // Merge in default callbacks.
        $callbacks = array(
          'rate',
          'details_form',
          'details_form_validate',
          'details_form_submit',
        );
        foreach ($callbacks as $callback) {
          if (!isset($shipping_service['callbacks'][$callback])) {
            $shipping_service['callbacks'][$callback] = $shipping_service['base'] . '_' . $callback;
          }
        }
        $shipping_services[$name] = $shipping_service;
      }
    }

    // Last allow the info to be altered by other modules.
    drupal_alter('commerce_shipping_service_info', $shipping_services);
  }

  // Filter out services that don't match the specified shipping method filter.
  if (!empty($method)) {
    $filtered_services = $shipping_services;
    foreach ($filtered_services as $name => $shipping_service) {
      if ($shipping_service['shipping_method'] != $method) {
        unset($filtered_services[$name]);
      }
    }
    return $filtered_services;
  }
  return $shipping_services;
}