Merge Cart

Developer tasks for using service method MergeCart.

MergeCart is used to combine the line items contained in two separate carts into a new third cart with its own unique ExternalID. The source carts are not changed by the method.

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");
    string anonymousUserId = Guid.NewGuid().ToString("B"); 
    var loadRequest = new LoadCartByNameRequest("Website","MyBasket", userId);
    var loadResult = provider.LoadCart(loadRequest); CommerceCarttoCart = loadResult.Cart as CommerceCart; 
    loadRequest = newLoadCartByNameRequest("Website", "MyBasket" anonymousUserId);
    loadResult = provider.LoadCart(loadRequest); 
    CommerceCart fromCart = loadResult.Cart as CommerceCart; 
    var mergeRequest = new MergeCartRequest(fromCart, toCart);