class CartEventSubscriber in Commerce Core 8.2
Same name in this branch
- 8.2 modules/log/src/EventSubscriber/CartEventSubscriber.php \Drupal\commerce_log\EventSubscriber\CartEventSubscriber
- 8.2 modules/cart/src/EventSubscriber/CartEventSubscriber.php \Drupal\commerce_cart\EventSubscriber\CartEventSubscriber
- 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\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CartEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
CartEventSubscriber:: |
public | function | Removes coupons when the cart has been emptied. |