Update Cart Lines
Abstract
Developer tasks for using service method UpdateCartLines
.
UpdateCartLines
is used when:
The quantity is changed
A service is added (like insurance or shipping)
A promotion code is added for a given product
A product is replaced with a variant
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; CommerceCartLine cartline = cart.Lines.ElementAt(0) as CommerceCartLine; cartline.Quantity = 4; var updateRequest = new UpdateCartLinesRequest(cart, new List<CartLine> { cartline }); // 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(updateRequest, "default"); var updateResult = provider.UpdateCartLines(updateRequest);