Add Promotional Code

Developer tasks for using service method AddPromoCode.

AddPromoCode is used to add promotional codes to a cart.

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. To use the service method, paste the following code:
    var provider = new CartServiceProvider();
    var userId = Guid.NewGuid().ToString();
    var loadCartRequest = new LoadCartByNameRequest("MyWebShop", "MyCart", userId);
    var cart = provider.LoadCart(loadCartRequest).Cart;
    var request = new AddPromoCodeRequest(cart, "12345");           
    var result = provider.AddPromoCode(request);