You are here

function commerce_shipping_entity_bundle_info_alter in Commerce Shipping 8.2

Implements hook_entity_bundle_info_alter().

File

./commerce_shipping.module, line 59
Provides core shipping functionality.

Code

function commerce_shipping_entity_bundle_info_alter(&$bundles) {
  if (empty($bundles['commerce_order'])) {
    return;
  }
  $order_type_ids = array_keys($bundles['commerce_order']);
  $order_types = OrderType::loadMultiple($order_type_ids);
  foreach ($bundles['commerce_order'] as $bundle => $info) {
    if (!isset($order_types[$bundle])) {
      continue;
    }
    $order_type = $order_types[$bundle];
    $shipment_type_id = $order_type
      ->getThirdPartySetting('commerce_shipping', 'shipment_type');
    if (!$shipment_type_id) {
      continue;
    }
    $shipment_type = ShipmentType::load($shipment_type_id);
    if (!$shipment_type) {
      continue;
    }

    // Bundle info is loaded on most requests. Store the shipping profile
    // type ID inside, so that it can be retrieved from the checkout pane
    // without having to load two bundle entities (order/shipment type).
    $shipping_profile_type_id = $shipment_type
      ->getProfileTypeId();
    if ($shipping_profile_type_id != 'customer') {

      // As a further optimization, the profile type ID is only stored
      // if it's different from the default ("customer").
      $bundles['commerce_order'][$bundle]['shipping_profile_type'] = $shipping_profile_type_id;
    }
  }
}