Update Cart

Current version: 8.2

Developer tasks for using service method UpdateCart.

UpdateCart is used to pass an updated cart to the external commerce system after any operation that modifies the cart. Typically when adjustments have been added, removed or modified.

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.

    CartServiceProvider provider = new CartServiceProvider(); 
    // You should get a real user id.
    string userId = Guid.NewGuid().ToString("B"); 
    var loadRequest = new LoadCartByNameRequest(UnitTestConstants.ObecDefaults.ShopName,"MyBasket", userId);
    var loadResult = provider.LoadCart(loadRequest); 
    CommerceCart cart = loadResult.Cart as CommerceCart; 
    CartBase changes = new CartBase(); changes.Properties.Add("MyWeaklyTypedProperty", "MyValue");
    changes.Status = "MyNewStatus"; 
    var updateRequest = new UpdateCartRequest(cart, changes); 
    var updateResult = provider.UpdateCart(updateRequest);

Do you have some feedback for us?

If you have suggestions for improving this article,