You are here

public function ShippingOrderManager::createProfile in Commerce Shipping 8.2

Creates a shipping profile for the given order.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

array $values: (optional) An array of field values to set on the profile.

Return value

\Drupal\profile\Entity\ProfileInterface A shipping profile.

Overrides ShippingOrderManagerInterface::createProfile

1 call to ShippingOrderManager::createProfile()
ShippingOrderManager::pack in src/ShippingOrderManager.php
Packs the given order into shipments.

File

src/ShippingOrderManager.php, line 52

Class

ShippingOrderManager

Namespace

Drupal\commerce_shipping

Code

public function createProfile(OrderInterface $order, array $values = []) {
  $values += [
    'type' => 'customer',
    'uid' => 0,
  ];

  // Check whether the order type has another profile type ID specified.
  $order_type_id = $order
    ->bundle();
  $order_bundle_info = $this->entityTypeBundleInfo
    ->getBundleInfo('commerce_order');
  if (!empty($order_bundle_info[$order_type_id]['shipping_profile_type'])) {
    $values['type'] = $order_bundle_info[$order_type_id]['shipping_profile_type'];
  }

  /** @var \Drupal\profile\ProfileStorageInterface $profile_storage */
  $profile_storage = $this->entityTypeManager
    ->getStorage('profile');
  return $profile_storage
    ->create($values);
}