You are here

protected function ShippingInformation::getShippingProfile in Commerce Shipping 8.2

Gets the shipping profile.

The shipping profile is assumed to be the same for all shipments. Therefore, it is taken from the first found shipment, or created from scratch if no shipments were found.

Return value

\Drupal\profile\Entity\ProfileInterface The shipping profile.

1 call to ShippingInformation::getShippingProfile()
ShippingInformation::buildPaneForm in src/Plugin/Commerce/CheckoutPane/ShippingInformation.php
Builds the pane form.

File

src/Plugin/Commerce/CheckoutPane/ShippingInformation.php, line 513

Class

ShippingInformation
Provides the shipping information pane.

Namespace

Drupal\commerce_shipping\Plugin\Commerce\CheckoutPane

Code

protected function getShippingProfile() {
  $shipping_profile = NULL;

  /** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
  foreach ($this->order
    ->get('shipments')
    ->referencedEntities() as $shipment) {
    $shipping_profile = $shipment
      ->getShippingProfile();
    break;
  }
  if (!$shipping_profile) {
    $profile_type_id = 'customer';

    // Check whether the order type has another profile type ID specified.
    $order_type_id = $this->order
      ->bundle();
    $order_bundle_info = $this->entityTypeBundleInfo
      ->getBundleInfo('commerce_order');
    if (!empty($order_bundle_info[$order_type_id]['shipping_profile_type'])) {
      $profile_type_id = $order_bundle_info[$order_type_id]['shipping_profile_type'];
    }
    $shipping_profile = $this->entityTypeManager
      ->getStorage('profile')
      ->create([
      'type' => $profile_type_id,
      'uid' => 0,
    ]);
  }
  return $shipping_profile;
}