You are here

class CheckoutEventSubscriber in Commerce Core 8.2

Hierarchy

  • class \Drupal\commerce_log\EventSubscriber\CheckoutEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CheckoutEventSubscriber

File

modules/log/src/EventSubscriber/CheckoutEventSubscriber.php, line 10

Namespace

Drupal\commerce_log\EventSubscriber
View source
class CheckoutEventSubscriber implements EventSubscriberInterface {

  /**
   * The log storage.
   *
   * @var \Drupal\commerce_log\LogStorageInterface
   */
  protected $logStorage;

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

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      CheckoutEvents::COMPLETION => [
        'onCheckoutCompletion',
        -100,
      ],
    ];
  }

  /**
   * Creates a log when the customer completes checkout.
   *
   * @param \Drupal\commerce_order\Event\OrderEvent $event
   *   The order event.
   */
  public function onCheckoutCompletion(OrderEvent $event) {
    $order = $event
      ->getOrder();
    $this->logStorage
      ->generate($order, 'checkout_complete')
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CheckoutEventSubscriber::$logStorage protected property The log storage.
CheckoutEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CheckoutEventSubscriber::onCheckoutCompletion public function Creates a log when the customer completes checkout.
CheckoutEventSubscriber::__construct public function Constructs a new CheckoutEventSubscriber object.