public function ConfirmationMessageSubscriber::onAddToCart in Commerce add to cart confirmation 1.x
Handles the add to cart event.
Parameters
\Drupal\commerce_cart\Event\CartEntityAddEvent $event:
File
- src/EventSubscriber/ ConfirmationMessageSubscriber.php, line 58 
Class
- ConfirmationMessageSubscriber
- Event Subscriber ConfirmationMessageSubscriber.
Namespace
Drupal\commerce_add_to_cart_confirmation\EventSubscriberCode
public function onAddToCart(CartEntityAddEvent $event) {
  $view = Views::getView('confirm_message_product_display');
  $view
    ->setDisplay('default');
  $view
    ->setArguments([
    $event
      ->getOrderItem()
      ->id(),
  ]);
  $confirmation_message = [
    '#theme' => 'commerce_add_to_cart_confirmation',
    '#title' => $view
      ->getTitle(),
    '#message' => $view
      ->render(),
    '#order_item' => $event
      ->getOrderItem(),
  ];
  $this->messenger
    ->addMessage($this->renderer
    ->render($confirmation_message), 'commerce-add-to-cart-confirmation');
}