You are here

public function CartRemoveItemResource::delete in Commerce Cart API 8

DELETE an 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.

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

Return value

\Drupal\rest\ModifiedResourceResponse The response.

See also

\Drupal\rest\EventSubscriber\ResourceResponseSubscriber::getResponseFormat

File

src/Plugin/rest/resource/CartRemoveItemResource.php, line 41

Class

CartRemoveItemResource
Provides a cart collection resource for current session.

Namespace

Drupal\commerce_cart_api\Plugin\rest\resource

Code

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