Lock Cart

Developer tasks for using service method LockCart.

LockCart is used to: If the cart is locked when LockCart is called, the pipeline is aborted and nothing happens. Is typically executed during the checkout process, just before any payment transaction is about to be executed and before turning the cart into an order. LockCart is triggered when a user in the checkout flow has selected “confirm” and in a B2C scenario, is going to pay, and the order is created.

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("Website","MyBasket", userId);
    var loadResult = provider.LoadCart(loadRequest); 
    CommerceCart cart = loadResult.Cart as CommerceCart; 
    LockCartRequest request = new LockCartRequest(cart); 
    var result = provider.LockCart(request);