You are here

public function Cart::emptyCart in Ubercart 8.4

Empties a cart of its contents.

Overrides CartInterface::emptyCart

File

uc_cart/src/Cart.php, line 178

Class

Cart
Utility class providing methods for the management of shopping carts.

Namespace

Drupal\uc_cart

Code

public function emptyCart() {
  $result = \Drupal::entityQuery('uc_cart_item')
    ->condition('cart_id', $this->id)
    ->execute();
  if (!empty($result)) {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('uc_cart_item');
    $entities = $storage
      ->loadMultiple(array_keys($result));
    $storage
      ->delete($entities);
  }
}