Work with orders fulfillment (C#)
The Orders Entity Views and Actions API supports operations to set the fulfillment of an order. Fulfillment information defines the means by which the items that constitute the order are transferred to the customer. You can set fulfillment to apply to an entire order or to apply to individual line items within the order.
You can only set fulfillment for orders that are on hold .
The following examples describe how to:
Set order fulfillment (C#)
You can set the fulfillment at the order level so that fulfillment information applies to all line orders within the order.
To set fulfillment of an order, for example for tangible items, using C#:
-
Get the entity view and specify a fulfillment option, for example
ShipToMe:RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "OrderFulfillmentDetails", "SelectFulfillmentOption", string.Empty); EntityView view = Proxy.GetValue(query); var optionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option")); var availableOptionsPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); optionProperty.Value = availableOptionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("ShipToMe")).Name; CommerceCommand command = Proxy.DoCommand(container.DoAction(view)); -
Specify the country for the shipping address:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var countryProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Country")); countProperty.Value = "3"; var availableCountryPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); countryProperty.Value = availableCountryPolicy?.List.FirstOrDefault(o => o.Name.Equals("CA")).Name; command = Proxy.DoCommand(container.DoAction(view)); -
Provide the remaining address properties, for example:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var stateProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("State")); var availableStatesPolicy = stateProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); stateProperty.Value = availableStatesPolicy?.List.FirstOrDefault(o => o.Name.Equals("ON")).Name; view.Properties.FirstOrDefault(p => p.Name.Equals("AddressName")).Value = "home"; view.Properties.FirstOrDefault(p => p.Name.Equals("FirstName")).Value = "john"; view.Properties.FirstOrDefault(p => p.Name.Equals("LastName")).Value = "doe"; view.Properties.FirstOrDefault(p => p.Name.Equals("Address1")).Value = "123 street A"; view.Properties.FirstOrDefault(p => p.Name.Equals("City")).Value = "city"; view.Properties.FirstOrDefault(p => p.Name.Equals("ZipPostalCode")).Value = "a1b2c3d"; view.Properties.FirstOrDefault(p => p.Name.Equals("PhoneNumber")).Value = "123 123 1234"; command = Proxy.DoCommand(container.DoAction(view)); -
Select the fulfillment method. The following example uses ground transportation:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var methodProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("State"));var availableMethodsPolicy = methodProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); methodProperty.Value = availableMethodsPolicy?.List.FirstOrDefault(o => o.DisplayName.Equals("Ground")).Name; command = Proxy.DoCommand(container.DoAction(view));
Set order lines fulfillment for split shipping (C#)
Some business scenarios require fulfillment to apply at the line item level. The following example shows a split shipping scenario, where two line items within the same order use different fulfillment options. Line item #1 represents a tangible product that uses ground shipping and requires street address details for delivery. Line item #2 represents a digital product that requires an email address for delivery.
To set order fulfillment options at the line level for split shipping:
-
Set the order fulfillment option to split shipping to provide the ability to specify distinct fulfillment details for each line item:
RequestResponseDataServiceQuerySingle<EntityView> query = container.GetEntityView($"Entity-Order-{orderId}", "OrderFulfillmentDetails", "SelectFulfillmentOption", string.Empty); EntityView view = Proxy.GetValue(query); var optionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option")); var availableOptionsPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); optionProperty.Value = availableOptionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("SplitShipping")).Name; CommerceCommand command = Proxy.DoCommand(container.DoAction(view)); -
To set the fulfillment information for Line item #1 (in this example a tangible product), select the fulfillment options for Line item #1:
RequestResponseEntityView view = Proxy.GetValue(query); var optionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option")); var availableOptionsPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); optionProperty.Value = availableOptionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("ShipToMe")).Name; CommerceCommand command = Proxy.DoCommand(container.DoAction(view)); -
Specify the country for Line item #1, for example:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var countryProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Country")); countProperty.Value = "3"; var availableCountryPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); countryProperty.Value = availableCountryPolicy?.List.FirstOrDefault(o => o.Name.Equals("CA")).Name; command = Proxy.DoCommand(container.DoAction(view)); -
Provide the rest of the address properties for Line item #1, for example:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var stateProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("State")); var availableStatesPolicy = stateProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); stateProperty.Value = availableStatesPolicy?.List.FirstOrDefault(o => o.Name.Equals("ON")).Name; view.Properties.FirstOrDefault(p => p.Name.Equals("AddressName")).Value = "home"; view.Properties.FirstOrDefault(p => p.Name.Equals("FirstName")).Value = "john"; view.Properties.FirstOrDefault(p => p.Name.Equals("LastName")).Value = "doe"; view.Properties.FirstOrDefault(p => p.Name.Equals("Address1")).Value = "123 street A"; view.Properties.FirstOrDefault(p => p.Name.Equals("City")).Value = "city"; view.Properties.FirstOrDefault(p => p.Name.Equals("ZipPostalCode")).Value = "a1b2c3d"; view.Properties.FirstOrDefault(p => p.Name.Equals("PhoneNumber")).Value = "123 123 1234"; command = Proxy.DoCommand(container.DoAction(view)); -
Set the fulfillment method (in this case, for ground shipping) for Line item #1:
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); var methodProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("State")); var availableMethodsPolicy = methodProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); methodProperty.Value = availableMethodsPolicy?.List.FirstOrDefault(o => o.DisplayName.Equals("Ground")).Name; command = Proxy.DoCommand(container.DoAction(view)); -
To set fulfillment information for Line item #2 (in this example, a non-tangible product), select the line fulfillment option
Digital:RequestResponseEntityView view = Proxy.GetValue(query); var optionProperty = view.Properties.FirstOrDefault(p => p.Name.Equals("Option")); var availableOptionsPolicy = optionProperty.Policies.OfType<AvailableSelectionsPolicy>().FirstOrDefault(); optionProperty.Value = availableOptionsPolicy?.List.FirstOrDefault(o => o.Name.Equals("Digital")).Name; CommerceCommand command = Proxy.DoCommand(container.DoAction(view)); -
Enter the email address (for example, [email protected] ) and the content of the email message (for example, Happy birthday!):
RequestResponseview = command.Models.OfType<EntityView>().FirstOrDefault(v => v.Name.Equals(view.Name)); view.Properties.FirstOrDefault(p => p.Name.Equals("EmailAddress")).Value = "[email protected]"; view.Properties.FirstOrDefault(p => p.Name.Equals("EmailContent")).Value = "Happy birthday!"; command = Proxy.DoCommand(container.DoAction(view));