Loading...

Last updated: Feb 12 2018

Area: Episerver Commerce Applies to versions: 10 and higher
Other versions:

Order processing

This topic describes the APIs for order processing in Episerver Commerce.

Namespaces and classes

When processing orders, refer to the namespace EPiServer.Commerce.Order, specifically these classes:

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 item

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.

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 wise to check if the product price has changed and, if so, to update the price so the business does not lose money.

Apply discount

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 apply discounts.

Process payments

Process payments allow the configured payments to be processed through their respective payment providers.

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.

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.

Process purchase orders

EPiServer.Commerce.Order.IPurchaseOrderProcessor

  • HoldOrder(). puts purchase order on hold.

  • ReleaseOrder(). releases a purchase order from hold.
  • CancelOrder(). cancels a purchase order.
  • ProcessOrder(). start processing a purchase order.

Process purchase order extensions

EPiServer.Commerce.Order.IPurchaseOrderExtensions

  • IsPaid(). determines if purchase order is paid.
  • CanBeCancelled(). determines if purchase order can be cancelled.
  • CanBePutOnHold(). determines if purchase order can be put on hold.
  • HasAwaitingStockReturns(). determines if purchase order has any awaiting stock returns.
  • HasAwaitingReturnCompletable(). determines if purchase order has any awaiting return completable.
  • GetActiveReturnForms(). gets purchase order's active return forms.
      
    Note:  This method was moved from DefaultReturnPurchaseOrderCalculator.
  • CanReleaseShipment(). determines if a shipment can be released.
  • CanCancelShipment(). determines if a shipment can be cancelled.
  • CanReturnShipment(). determines if a shipment can be returned.
  • CanCompleteShipment(). determines if a shipment can be completed.

Process shipments

EPiServer.Commerce.Order.IShipmentProcessor 

  • CancelShipment(). cancels a shipment.
  • CompleteShipment(). completes shipments.
  • ReleaseShipment(). releases shipments.
  • AddShipmentToPicklist(). adds a shipment to picklist.
  • RemoveShipmentFromPicklist(). removes a shipment from picklist.

Process payment plans

EPiServer.Commerce.Order.IPaymentPlanProcessor

  • CancelPaymentPlan(). cancels a payment plan.

Process payment plan extensions

EPiServer.Commerce.Order.IPaymentPlanExtensions 

  • IsPaid(). determines if a payment plan is paid.
  • CanBeCancelled(). determines if a payment plan can be cancelled.

Process shipment extensions

EPiServer.Commerce.Order.IShipmentProcessorExtensions

  • CompleteShipment(). completes a shipment.
  • ReleaseShipment(). releases a shipment.

EPiServer.Commerce.Order.IShipmentExtensions

  • CanBePacked(). determines if a shipment can be packed.
        

Note: The method GetActiveReturnForms() was removed from DefaultReturnPurchaseOrderCalculator. Use this method in IPurchaseOrderExtensions instead.

Checkout order using APIs

This section describes how to check out an order using APIs instead of workflow.

The default cart checkout workflow contains several activities that can be called separately by APIs:

  • ProcessPaymentActivity. Use to process payments added to a cart. This can be handled by IOrderGroupExtensions.ProcessPayments.
  • CalculateTotalsActivity. Use to calculate order totals. This can be handled by IOrderGroupExtensions.GetTotals().
  • AdjustInventoryActivityUse to adjust line item inventories. This can be handled by IOrderGroupExtensions.AdjustInventoryOrRemoveLineItems().
  • RecordPromotionUsageActivityUse to calculate and save promotion usage. This can be handled by IOrderGroupExtensions.ApplyDiscounts().

Finally, to save a cart as a purchase order, use IOrderRepository.SaveAsPurchaseOrder(). See also: CartHelper is dead, long live IOrderRepository.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/