You are here

class DefaultOrderTypeResolver in Commerce Core 8.2

Returns the order type, based on order item type configuration.

Hierarchy

Expanded class hierarchy of DefaultOrderTypeResolver

1 string reference to 'DefaultOrderTypeResolver'
commerce_order.services.yml in modules/order/commerce_order.services.yml
modules/order/commerce_order.services.yml
1 service uses DefaultOrderTypeResolver
commerce_order.default_order_type_resolver in modules/order/commerce_order.services.yml
Drupal\commerce_order\Resolver\DefaultOrderTypeResolver

File

modules/order/src/Resolver/DefaultOrderTypeResolver.php, line 11

Namespace

Drupal\commerce_order\Resolver
View source
class DefaultOrderTypeResolver implements OrderTypeResolverInterface {

  /**
   * The order item type storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $orderItemTypeStorage;

  /**
   * Constructs a new DefaultOrderTypeResolver object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->orderItemTypeStorage = $entity_type_manager
      ->getStorage('commerce_order_item_type');
  }

  /**
   * {@inheritdoc}
   */
  public function resolve(OrderItemInterface $order_item) {

    /** @var \Drupal\commerce_order\Entity\OrderItemTypeInterface $order_item_type */
    $order_item_type = $this->orderItemTypeStorage
      ->load($order_item
      ->bundle());
    return $order_item_type
      ->getOrderTypeId();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultOrderTypeResolver::$orderItemTypeStorage protected property The order item type storage.
DefaultOrderTypeResolver::resolve public function Resolves the order type. Overrides OrderTypeResolverInterface::resolve
DefaultOrderTypeResolver::__construct public function Constructs a new DefaultOrderTypeResolver object.