You are here

public function CartEventSubscriber::onCartEntityAdd in Commerce Core 8.2

Creates a log when an entity has been added to the cart.

Parameters

\Drupal\commerce_cart\Event\CartEntityAddEvent $event: The cart event.

File

modules/log/src/EventSubscriber/CartEventSubscriber.php, line 47

Class

CartEventSubscriber

Namespace

Drupal\commerce_log\EventSubscriber

Code

public function onCartEntityAdd(CartEntityAddEvent $event) {
  $cart = $event
    ->getCart();
  $this->logStorage
    ->generate($cart, 'cart_entity_added', [
    'purchased_entity_label' => $event
      ->getOrderItem()
      ->label(),
  ])
    ->save();
}