Last active
December 10, 2015 21:41
-
-
Save allenmichael/2ba3feedb2cc01618263 to your computer and use it in GitHub Desktop.
Fulfill digital items on an Order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Fulfill_Digital_Order() | |
{ | |
var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext); | |
var orderCollection = orderResource.GetOrdersAsync(filter: "orderNumber eq 393").Result; | |
var orderId = orderCollection.Items.Count > 0 ? orderCollection.Items[0].Id : null; | |
if (orderId != null) | |
{ | |
var order = orderResource.GetOrderAsync(orderId).Result; | |
var digitalPackageResource = new Mozu.Api.Resources.Commerce.Orders.DigitalPackageResource(_apiContext); | |
var digitalPackageItem = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.DigitalPackageItem() | |
{ | |
ProductCode = order.Items[0].Product.ProductCode, | |
Quantity = order.Items[0].Quantity | |
}; | |
var digitalPackage = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.DigitalPackage() | |
{ | |
Items = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.DigitalPackageItem>() { digitalPackageItem }, | |
FulfillmentLocationCode = "Digital", | |
}; | |
var packageResult = digitalPackageResource.CreateDigitalPackageAsync(digitalPackage, order.Id).Result; | |
order = orderResource.GetOrderAsync(orderId).Result; | |
var availableActions = order.AvailableActions.Count > 0 ? order.AvailableActions : null; | |
if (availableActions != null && availableActions.Exists(x => x == "FulfillDigitalItems")) | |
{ | |
var orderAction = new Mozu.Api.Contracts.CommerceRuntime.Orders.OrderAction() | |
{ | |
ActionName = "FulfillDigitalItems" | |
}; | |
var updatedOrder = orderResource.PerformOrderActionAsync(orderAction, orderId).Result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment