You are here

class CartEventSubscriber in Commerce Core 8.2

Same name in this branch
  1. 8.2 modules/log/src/EventSubscriber/CartEventSubscriber.php \Drupal\commerce_log\EventSubscriber\CartEventSubscriber
  2. 8.2 modules/cart/src/EventSubscriber/CartEventSubscriber.php \Drupal\commerce_cart\EventSubscriber\CartEventSubscriber
  3. 8.2 modules/promotion/src/EventSubscriber/CartEventSubscriber.php \Drupal\commerce_promotion\EventSubscriber\CartEventSubscriber

Hierarchy

  • class \Drupal\commerce_promotion\EventSubscriber\CartEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CartEventSubscriber

1 file declares its use of CartEventSubscriber
CommercePromotionServiceProvider.php in modules/promotion/src/CommercePromotionServiceProvider.php

File

modules/promotion/src/EventSubscriber/CartEventSubscriber.php, line 9

Namespace

Drupal\commerce_promotion\EventSubscriber
View source
class CartEventSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [
      CartEvents::CART_EMPTY => [
        'onCartEmpty',
      ],
    ];
    return $events;
  }

  /**
   * Removes coupons when the cart has been emptied.
   *
   * @param \Drupal\commerce_cart\Event\CartEmptyEvent $event
   *   The cart event.
   */
  public function onCartEmpty(CartEmptyEvent $event) {
    $event
      ->getCart()
      ->set('coupons', []);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CartEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CartEventSubscriber::onCartEmpty public function Removes coupons when the cart has been emptied.