You are here

public function CartClearResource::delete in Commerce Cart API 8

DELETE all order item from a cart.

The ResourceResponseSubscriber provided by rest.module gets weird when going through the serialization process. The method is not cacheable and it does not have a body format, causing it to be considered invalid.

@todo Investigate if we can return updated order as response.

Parameters

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

Return value

\Drupal\rest\ModifiedResourceResponse The response.

See also

\Drupal\rest\EventSubscriber\ResourceResponseSubscriber::getResponseFormat

File

src/Plugin/rest/resource/CartClearResource.php, line 38

Class

CartClearResource
Clear order items and reset the cart to initial.

Namespace

Drupal\commerce_cart_api\Plugin\rest\resource

Code

public function delete(OrderInterface $commerce_order) {
  $this->cartManager
    ->emptyCart($commerce_order);
  return new ModifiedResourceResponse(NULL, 204);
}