Delete Cart
Abstract
Developer tasks for using service method DeleteCart
.
DeleteCart
is used to delete a cart permanently. Uses include:
The user has gone through the B2C scenario of paying and an order has been created and registered.
A cart has been in abandoned state for a given time and the visitor is not expected to return.
At your Visual Studio solution setup:
Reference the Sitecore.Commerce.Connect.CommerceServer and Sitecore.Commerce.dll.
Pick the class in your solution where want to use this service method.
Paste in the code below to use the service method.
CartServiceProvider provider = new CartServiceProvider(); // You should get a real user id.string userId = Guid.NewGuid().ToString("B"); var loadRequest = new LoadCartByNameRequest("Website", "MyBasket", userId); var loadResult = provider.LoadCart(loadRequest); CommerceCart cart = loadResult.Cart as CommerceCart; DeleteCartRequest request = new DeleteCartRequest(cart);var result = provider.DeleteCart(request);