Lock Cart
Developer tasks for using service method LockCart
.
LockCart
is used to:
prevent modification the shopping cart content using the other service layer methods
compare and confirm with payment transactions whether there are carts that have not been finalized due to some unforeseen incident in the checkout process.
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:
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; LockCartRequest request = new LockCartRequest(cart); var result = provider.LockCart(request);