You are here

class OrderEventsSubscriber in Commerce Demo 8

Hierarchy

  • class \Drupal\commerce_demo\EventSubscriber\OrderEventsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of OrderEventsSubscriber

1 string reference to 'OrderEventsSubscriber'
commerce_demo.services.yml in ./commerce_demo.services.yml
commerce_demo.services.yml
1 service uses OrderEventsSubscriber
commerce_demo.order_events_subscriber in ./commerce_demo.services.yml
Drupal\commerce_demo\EventSubscriber\OrderEventsSubscriber

File

src/EventSubscriber/OrderEventsSubscriber.php, line 9

Namespace

Drupal\commerce_demo\EventSubscriber
View source
class OrderEventsSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[OrderEvents::ORDER_CREATE][] = [
      'onOrderCreate',
    ];
    return $events;
  }

  /**
   * Reacts to an order being created..
   *
   * @param \Drupal\commerce_order\Event\OrderEvent $event
   *   The order event.
   */
  public function onOrderCreate(OrderEvent $event) {
    $order = $event
      ->getOrder();
    if ($order
      ->getCustomer()
      ->isAnonymous()) {
      $order
        ->setEmail(sprintf('demo+%s@commercekickstart.com', time()));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderEventsSubscriber::getSubscribedEvents public static function
OrderEventsSubscriber::onOrderCreate public function Reacts to an order being created..