0

I can add an order item from the cart by doing this :

\Drupal::service('commerce_cart.cart_manager')->getStorage('commerce_order_item')->create(array())

Is there a similar way to delete a product line from my cart ?

3

Orders have a removeItem method defined on their interface. You just need to pass the loaded order item to that method, and then delete the orderitem.

/**
 * Removes an order item.
 *
 * @param \Drupal\commerce_order\Entity\OrderItemInterface $order_item
 *   The order item.
 *
 * @return $this
 */
public function removeItem(OrderItemInterface $order_item);
0

See how the commerce_xquantity module does this: https://github.com/drugan/commerce_xquantity/blob/8.x-1.x/src/Entity/XquantityOrderItem.php#L318

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.