Developer tasks for using service method UnlockCart.
UnlockCart is used to put the cart in an editable state. The
most common use is to modify the content after starting the checkout process and payment
transaction.
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;
UnlockCartRequest unlockRequest = new UnlockCartRequest(cart);
var result = provider.UnlockCart(unlockRequest);
Update cart
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;
CartBase changes = new CartBase(); changes.Properties.Add("MyWeaklyTypedProperty", "MyValue");
changes.Status = "MyNewStatus";
var updateRequest = new UpdateCartRequest(cart, changes);
var updateResult = provider.UpdateCart(updateRequest);