Remove Cart Lines

Current version: 8.2

Developer tasks for using service method RemoveCartLine.

RemoveCartLine is used to delete items from a specific cart.

At your Visual Studio solution setup:

  1. Reference the Sitecore.Commerce.Connect.CommerceServer and Sitecore.Commerce.dll.

  2. Pick the class in your solution where want to use this service method.

  3. Paste in the code below to use the service method.

    RequestResponse
    
    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;
    var cartline1 =new CommerceCartLine("Adventure Works Catalog", "AW190-11", "16", 1);
    var cartline2 = new CommerceCartLine("Adventure Works Catalog", "AW109-15", null,4);
    var removeRequest= new RemoveCartLinesRequest(cart,new List<CartLine> { cartline1, cartline2 }); 
    // Only required if you must specify the order form name to use.  If not specified the
    // first order form is used.
    var info = new CartRequestInformation(removeRequest, "default"); 
    var removeResult = provider.RemoveCartLines(removeRequest);
    

Do you have some feedback for us?

If you have suggestions for improving this article,