You are here

public function CartCollectionResource::get in Commerce Cart API 8

GET a collection of the current user's carts.

Return value

\Drupal\rest\ResourceResponse The resource response.

File

src/Plugin/rest/resource/CartCollectionResource.php, line 26

Class

CartCollectionResource
Provides a cart collection resource for current session.

Namespace

Drupal\commerce_cart_api\Plugin\rest\resource

Code

public function get() {
  $carts = $this->cartProvider
    ->getCarts();
  $response = new ResourceResponse(array_values($carts), 200);

  /** @var \Drupal\commerce_order\Entity\OrderInterface $cart */
  foreach ($carts as $cart) {
    $response
      ->addCacheableDependency($cart);
  }
  $response
    ->getCacheableMetadata()
    ->addCacheContexts([
    'store',
    'cart',
  ]);
  return $response;
}