You are here

public function CartManager::addEntity in Commerce Core 8.2

Adds the given purchasable entity to the given cart order.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $cart: The cart order.

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.

string $quantity: The quantity.

bool $combine: Whether the order item should be combined with an existing matching one.

bool $save_cart: Whether the cart should be saved after the operation.

Return value

\Drupal\commerce_order\Entity\OrderItemInterface The saved order item.

Overrides CartManagerInterface::addEntity

File

modules/cart/src/CartManager.php, line 84

Class

CartManager
Default implementation of the cart manager.

Namespace

Drupal\commerce_cart

Code

public function addEntity(OrderInterface $cart, PurchasableEntityInterface $entity, $quantity = '1', $combine = TRUE, $save_cart = TRUE) {
  $order_item = $this
    ->createOrderItem($entity, $quantity);
  return $this
    ->addOrderItem($cart, $order_item, $combine, $save_cart);
}