You are here

public function CartManager::emptyCart in Commerce Core 8.2

Empties the given cart order.

Parameters

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

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

Overrides CartManagerInterface::emptyCart

1 call to CartManager::emptyCart()
CartManager::removeOrderItem in modules/cart/src/CartManager.php
Removes the given order item from the cart order.

File

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

Class

CartManager
Default implementation of the cart manager.

Namespace

Drupal\commerce_cart

Code

public function emptyCart(OrderInterface $cart, $save_cart = TRUE) {
  $order_items = $cart
    ->getItems();
  foreach ($order_items as $order_item) {
    $order_item
      ->delete();
  }
  $cart
    ->setItems([]);
  $cart
    ->setAdjustments([]);
  $this->eventDispatcher
    ->dispatch(CartEvents::CART_EMPTY, new CartEmptyEvent($cart, $order_items));
  $this
    ->resetCheckoutStep($cart);
  if ($save_cart) {
    $cart
      ->save();
  }
}