Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function addLineItem(OrderInterface $cart, LineItemInterface $line_item, $combine = TRUE, $save_cart = TRUE)
 {
     $purchased_entity = $line_item->getPurchasedEntity();
     $quantity = $line_item->getQuantity();
     $matching_line_item = NULL;
     if ($combine) {
         $matching_line_item = $this->lineItemMatcher->match($line_item, $cart->getLineItems());
     }
     $needs_cart_save = FALSE;
     if ($matching_line_item) {
         $new_quantity = $matching_line_item->getQuantity() + $quantity;
         $matching_line_item->setQuantity($new_quantity);
         $matching_line_item->save();
     } else {
         $line_item->save();
         $cart->addLineItem($line_item);
         $needs_cart_save = TRUE;
     }
     $event = new CartEntityAddEvent($cart, $purchased_entity, $quantity, $line_item);
     $this->eventDispatcher->dispatch(CartEvents::CART_ENTITY_ADD, $event);
     if ($needs_cart_save && $save_cart) {
         $cart->save();
     }
     return $line_item;
 }