Add Cart Lines

Current version: 8.2

Developer tasks for using service method AddCartLine.

AddCartLine is used to add items to 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. To use the service method, paste the following code:

    var provider = new CartServiceProvider();
    // load or create the cart
    var loadCartRequest = new LoadCartByNameRequest("MyWebShop", "MyBasket", "UserId1");
    var cart = provider.LoadCart(loadCartRequest).Cart;
    var cartline = new CommerceCartLine("Adventure Works Catalog", "AW190-11", "16", 1);
    var addCartLinesRequest = new AddCartLinesRequest(cart, new List<CartLine> { cartline });
    var addCartLinesResult = provider.AddCartLines(addCartLinesRequest);
    // cart with newly added cartline
    cart = addCartLinesResult.Cart;

Do you have some feedback for us?

If you have suggestions for improving this article,