How to delete cart?

Vote:
 

After I have converted my cart to a purchase order, I want to delete the cart. How can I do that programmatically?

public void DeleteCart(ICart cart)
{
   // what to do here?
}

It's in Commerce 11.

#193887
Edited, Jun 07, 2018 9:47
Vote:
 

You can do it by using OrderRepository, like:

public void DeleteCart(ICart cart)
{
   // what to do here?
   OrderRepository.Service.Delete(cart.OrderLink);
}
#193891
Edited, Jun 07, 2018 10:23
Vote:
 

As addition to Giang's answer, you should use IOrderRepository, and you should inject it to your constructor as a best practice. 

After that, just

_orderRepository.Delete(cart.OrderLink);

#193902
Jun 07, 2018 12:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.