Processing of purchase orders and related items is based on classes and methods in the EPiServer.Commerce.Order and EPiServer.Commerce.Marketing namespaces.
These are the key interfaces:
EPiServer.Commerce.Order.IOrderGroupExtensions
EPiServer.Commerce.Order.IInventoryProcessor. See Updating inventory and Adjusting inventory.
EPiServer.Commerce.Order.ILineItemValidator. See Validating line item.
EPiServer.Commerce.Order.IPaymentProcessor. See Processing payments.
EPiServer.Commerce.Order.IPaymentPlanProcessor. See Processing payment plans.
EPiServer.Commerce.Order.IPaymentPlanExtensions. See Processing payment plan extensions.
EPiServer.Commerce.Order.IPlacedPriceProcessor. See Updating placed price.
EPiServer.Commerce.Order.IFulfillmentWarehouseProcessor
EPiServer.Commerce.Order.IPurchaseOrderProcessor . See Processing purchase orders.
EPiServer.Commerce.Order.IPurchaseOrderExtensions. See Processing purchase order extensions.
EPiServer.Commerce.Order.IShipmentProcessor. See Processing shipments.
EPiServer.Commerce.Order.IShipmentProcessorExtensions. See Processing shipment extensions.
EPiServer.Commerce.Order.IShipmentExtensions. See Processing shipment extensions.
EPiServer.Commerce.Marketing.IPromotionEngine. See Applying discount.
All example code below passes dependencies to the extension methods, so that you can easily unit test your applications.
## Validation issues
When performing different actions on an IOrderGroup, issues can cause modifications to line items. These warnings and errors are represented in the class EPiServer.Commerce.Order.ValidationIssue. Most processing tasks take a parameter with an Action\<ILineItem, ValidationIssue>, which allows the caller to collect this information so a message about the issue can be displayed to the user.
## Validate line items
Validating the status of line item is useful to make sure the product is active, within the valid date range, and that the catalog entry is available in the current market.
**Example:** Validating line items in a cart and checking for validation issues.
## Update placed price
Updating placed price is useful when a shopper has an item in the cart for an extended period of time. It is recommended to add validation to check if the product price has changed, and if needed update the price.
**Example:** Checking and updating placed price for line items.
## Apply discounts
Applying discounts will run the promotion engine to evaluate and apply discounts to the IOrderGroup. If certain discounts require coupons, it is important to add coupons to the IOrderForm before running ApplyDiscounts.
**Example:** Checking for discounts on items in a cart.
## Process payments
Process payments allow the configured payments to be processed through their respective payment providers.
**Example:** Running the payment processor for a cart.
## Update inventory
UpdateInventory checks that a sufficient inventory quantity exists for the selected shipment warehouse. This method also updates the line item with the available quantity or, if none are available, removes it.
**Example:** Updating inventory information for a cart.
## Adjust inventory
AdjustInventory adjusts the inventory for each line item and removes it if no inventory exists. This operation is done in sequence for each shipment in an IOrderGroup, or for a specific shipment if the IInventoryProcessor method is called directly.
The behavior changes based on the value of the IOrderGroup OrderStatus property. If calling the IInventoryProcessor directly, you should pass the status of the shipment's parent IOrderGroup:
**Completed** – Makes permanent the reservation of inventory, decrementing available quantity.
**Canceled** – Cancels the reservation of inventory, incrementing available quantity.
**InProgress** \|\| **AwaitingExchange** – Reserves inventory to fulfill the shipment.
In addition, the value of IShipment.OrderShipmentStatus may override the behavior for a specific shipment.
**Shipped** – Same behavior as OrderStatus.Completed but is applied regardless of the value of IOrderGroup.OrderStatus.
**Cancelled** – Same behavior as OrderStatus.Cancelled but is applied regardless of the value of IOrderGroup.OrderStatus.
**Example:** Adjusting inventory information for a line items in a cart.
## Process purchase orders
IPurchaseOrderProcessor contains functionality for putting and releasing orders on hold, canceling orders, and starting order processing.
**Example:** Using HoldOrder() to put a purchase order on hold.
**Example:** Using CancelOrder() to cancel a purchase order.
**Example:**Â Using ProcessOrder() to start processing a purchase order.
## Process purchase order extensions
IPurchaseOrderExtensions extends the functionality provided with IPurchaseOrderProcessor.
**Example:** Using IsPaid() to determine if a purchase order is paid.
**Example:** Using CanBeCancelled()Â to determine if purchase order can be cancelled.
**Example:** Using CanBePutOnHold()Â to determine if purchase order can be put on hold.
**Example:** Using HasAwaitingStockReturns()Â to determine if purchase order has any awaiting stock returns.
**Example:** Using HasAwaitingReturnCompletable()Â to determine if purchase order has any awaiting return completable.
**Example:** Using GetActiveReturnForms()Â to get a purchase order's active return forms (moved from DefaultReturnPurchaseOrderCalculator).
**Example:** Using CanReleaseShipment()Â to determine if a shipment can be released.
**Example:** Using CanCancelShipment()Â to determine if a shipment can be cancelled.
**Example:** Using CanReturnShipment()Â to determine if a shipment can be returned.
**Example:** Using CanCompleteShipment() to determine if a shipment can be completed.
## Process shipments
IShipmentProcessor contains functionality for canceling, completing, and realising shipments, and adding them to and from warehouse picklists.
**Example:** Using CancelShipment() to cancel a shipment.
**Example:** Using CompleteShipment() to complete a shipment.
**Example:** Using ReleaseShipment()Â to release a shipment.
**Example:** Using AddShipmentToPicklist()Â to add a shipment to a picklist.
**Example:** Using RemoveShipmentFromPicklist()Â to remove a shipment from a picklist.
## Process shipment extensions
IShipmentProcessorExtensions extends the functionality provided with IShipmentProcessor.
**Example:** Using CompleteShipment() to complete a shipment.
**Example:** Using ReleaseShipment() to release a shipment.
**Example:** Using CanBePacked()Â in IShipmentExtensions to determine if a shipment can be packed.
## Process payment plans
IPaymentPlanProcessor contains functionality for canceling payment plans.
**Example:** Using CancelPaymentPlan() to cancel a payment plan.
## Process payment plan extensions
IPaymentPlanExtensions conatins functionality for checking payment and cancellation of payment plans.
**Example:** Using IsPaid() to determine if a payment plan is paid.
**Example:** Using CanBeCancelled() to determine if a payment plan can be cancelled.
## Use APIs instead of CartHelper for order checkout
The IOrderRepository API replaces the legacy functionality provided with the CartHelper activity workflow. The following provides some guidelines on how to use the API instead.
The legacy cart checkout workflow contained activities that can be called separately by the APIs.
ProcessPaymentActivity – Previously used for processing payments added to a cart. Use IOrderGroupExtensions.ProcessPayments instead.
CalculateTotalsActivity – Previously used for calculating order totals. Use IOrderGroupExtensions.GetTotals() instead.
AdjustInventoryActivity – Previously used for adjusting line item inventories. Use IOrderGroupExtensions.AdjustInventoryOrRemoveLineItems() instead.
RecordPromotionUsageActivity – Previously used to calculate and save promotion usage. Use IOrderGroupExtensions.ApplyDiscounts() instead.
Use IOrderRepository.SaveAsPurchaseOrder()Â to save a cart as a purchase order.