You are here

public function CartManager::removeOrderItem in Commerce Core 8.2

Removes the given order item from the cart order.

Parameters

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

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

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

Overrides CartManagerInterface::removeOrderItem

File

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

Class

CartManager
Default implementation of the cart manager.

Namespace

Drupal\commerce_cart

Code

public function removeOrderItem(OrderInterface $cart, OrderItemInterface $order_item, $save_cart = TRUE) {
  $order_item
    ->delete();
  $cart
    ->removeItem($order_item);
  $this->eventDispatcher
    ->dispatch(CartEvents::CART_ORDER_ITEM_REMOVE, new CartOrderItemRemoveEvent($cart, $order_item));

  // If this results in an empty cart call the emptyCart method for
  // consistency.
  if ($cart
    ->get('order_items')
    ->isEmpty()) {
    $this
      ->emptyCart($cart, $save_cart);
    return;
  }
  $this
    ->resetCheckoutStep($cart);
  if ($save_cart) {
    $cart
      ->save();
  }
}