You are here

class OrderAssignment in Commerce Core 8.2

Hierarchy

Expanded class hierarchy of OrderAssignment

1 string reference to 'OrderAssignment'
commerce_order.services.yml in modules/order/commerce_order.services.yml
modules/order/commerce_order.services.yml
1 service uses OrderAssignment
commerce_order.order_assignment in modules/order/commerce_order.services.yml
Drupal\commerce_order\OrderAssignment

File

modules/order/src/OrderAssignment.php, line 12

Namespace

Drupal\commerce_order
View source
class OrderAssignment implements OrderAssignmentInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The event dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * Constructs a new OrderAssignment object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $event_dispatcher) {
    $this->entityTypeManager = $entity_type_manager;
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * {@inheritdoc}
   */
  public function assign(OrderInterface $order, UserInterface $customer, $save_order = TRUE) {

    // Notify other modules before the order is modified, so that
    // subscribers have access to the original data.
    $event = new OrderAssignEvent($order, $customer);
    $this->eventDispatcher
      ->dispatch(OrderEvents::ORDER_ASSIGN, $event);
    $order
      ->setCustomer($customer);
    $order
      ->setEmail($customer
      ->getEmail());
    if ($save_order) {
      $order
        ->save();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function assignMultiple(array $orders, UserInterface $customer) {
    foreach ($orders as $order) {
      $this
        ->assign($order, $customer);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderAssignment::$entityTypeManager protected property The entity type manager.
OrderAssignment::$eventDispatcher protected property The event dispatcher.
OrderAssignment::assign public function Assigns the order to the given customer. Overrides OrderAssignmentInterface::assign
OrderAssignment::assignMultiple public function Assigns multiple orders to the given customer. Overrides OrderAssignmentInterface::assignMultiple
OrderAssignment::__construct public function Constructs a new OrderAssignment object.