HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Workflows and activities

Describes how you can work with validation services and processors in Optimizely Customized Commerce 13.

In Optimizely Customized Commerce, activity flows are used for validation and calculating totals in the checkout process. An activity flow is a container of steps, or activities, which can be executed. When executing an activity flow, a list of configured activities and if/else conditions is executed.

Several default activity flows are included (Mediachase.Commerce.Workflow project). Checkout activities, like calculating cart totals, updating inventory, and processing payments, are handled outside of the core API using the Activity Flow engine.

The result of executing an activity flow is a WorkflowResults object, which contains:

  • The dictionary of output parameter, which are all context properties that were used and updated while running the activity flow.
  • The exceptions if any.
  • The Workflow Status, to indicate if the activity flow is completed or aborted.

Each activity flow contains several activities, each with a distinct purpose, such as calculating discounts. You can reuse activities among activity flows. This division provides greater flexibility and easier management of business rules. To change the business rules associated with checkout, Optimizely Customized Commerce lets you incorporate your own workflows. See Customize order processing activity flows.

Classes in this topic are available in the following namespaces:

  • Mediachase.Commerce.Workflow
  • Mediachase.Commerce.Workflow.Activities
  • Mediachase.Commerce.Workflow.Activities.Cart
  • Mediachase.Commerce.Workflow.Activities.PurchaseOrderActivities



The legacy activity flows and activities in the namespace Mediachase.Commerce.Workflow.Legacy and Mediachase.Commerce.Workflow.Legacy.Activities, which use the legacy system and work with the old promotion system. By default, these will be disabled. To enable it, see Promotion engine.

Activity flows


Calculates shopping cart totals, including discounts, and validates if a product is available. This activity flow is executed every time the cart view page is loaded. It is called in the CartViewModule.ascx control, which renders the cart. It uses the following activities, in order:

  • ValidateLineItemsActivity
  • GetFulfillmentWarehouseActivity
  • CheckInventoryActivity
  • RemoveDiscountsActivity. Discounts are removed so pre-discount totals can be calculated in the next step.
  • CalculateDiscountsActivity
  • CalculateTotalsActivity. A calculation of totals that includes discounts.


Associates line items with shipments in the OrderForm object (allows split shipment), calculates shipment prices, tax totals, order total. Shipments require a custom shipping provider. The flow uses interfaces that your shipment and tax providers implement.

This activity flow is executed just prior to completing the order. Its calculations ensure that the cart includes all relevant discounts and ancillary costs, such as taxes and shipping charges. It uses the following activities, in order:

  • ValidateLineItemsActivity
  • GetFulfillmentWarehouseActivity
  • CheckInventoryActivity
  • RemoveDiscountsActivity. Discounts are removed so pre-discount and pre-tax totals can be calculated in the next step.
  • CalculateDiscountsActivity
  • UpdateTotalsActivity 


Validates order total and processes payment (again, requires custom payment provider). This flow is executed upon submission of the cart for processing. It uses the following activities, in order:

  • ProcessPaymentActivity. If ActivityFlow.ShouldProcessPayment is set to True.
  • CalculateTotalsActivity
  • AdjustInventoryActivity


  • AdjustInventoryActivity – If inventory tracking is enabled, adjusts SKU inventory after purchase.
  • CalculateDiscountsActivity – Calculates discounts associated with each line item, shipment discounts, and order discounts. Discounts are saved in line item Discounts, Shipment's Discounts collection, and OrderForm Discounts collection.
  • CalculateTaxActivity – Calculates tax associated with order. See also: Taxes.
  • CalculateTotalsActivity – Calculates cart total based on line item price and quantity, shipping totals, handling totals, and taxes. OrderForm, Cart, and line item properties regarding totals are updated.
  • CheckInventoryActivity – If inventory tracking is enabled, determines whether sufficient stock is on hand for each line item. If not, quantities of SKUs greater than stock are removed and warnings returned to indicate the cart change.
  • ProcessHandlingActivity – No implementation is included.
  • ProcessPaymentActivity – Calls the ProcessPayment method associated with the cart's payment providers.
  • CapturePaymentActivity – Captures the payment when completing the shipment.
  • RecordPromotionUsageActivity – Saves promotion usage data to the PromotionUsage table, which tracks promotion entries for enforcement of promotion redemption limits.
  • RemoveDiscountsActivity – Empties the discount collections associated with LineItem, Shipment, and OrderForm instances.
  • ShipmentSplitActivity – Associates cart items with shipments to which they have been previously added. The list of items in each shipment are stored in LineItemIndexes field.
  • ValidateLineItemsActivity –
    • Transfers catalog entry inventory properties to each line item.
    • Returns error message if a line item price changed or line item quantity is reduced due to an inventory shortage.
    • Removes SKUs (with an error message returned) that are no longer active, or are members of inactive catalogs.


  • Activity flows are executed using the OrderGroupWorkFlowManager.RunWorkflow() method.

    public static WorkflowResults RecalculatePurchaseOrder(PurchaseOrder purchaseOrder, bool throwException)
     if (purchaseOrder == null)
         throw new ArgumentNullException(nameof(purchaseOrder));
     return OrderGroupWorkflowManager.RunWorkflow(purchaseOrder, OrderGroupWorkflowManager.OrderRecalculateWorkflowName, throwException);
  • Errors from activities can be of numerous types. A common way to handle exceptions is to wrap a Try/Catch around the RunWorkflow method, then use the ErrorManager GenerateError() method to publish the event to any listeners attached to the ErrorManagers Error event.

  • You can create custom activity flows and activities in your project. See Customize order processing activity flows.