Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Navigation [hide] [expand]
ARCHIVED This content is retired and no longer maintained. See the latest version here.

In Commerce 9, Microsoft Windows Workflow Foundation was removed and replaced with Mediachase.Commerce.Engine.ActivityFlow and Mediachase.Commerce.WorkflowCompatibility.Activity. 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 performed.

How it works

In Episerver Commerce, activity flows are used for validation and calculating totals in the checkout process. 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 were used, and were updated while running the activity flow.
  • The exception if any.
  • The Workflow Status, to tell 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, Episerver Commerce lets you incorporate your own workflows. See Customizing Order Processing Activity Flows for more information.

Classes in this topc are available in the following namespaces:

Key files and controls

Activity flows

CartValidateActivityFlow

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
  • CheckInventoryActivity
  • RemoveDiscountsActivity. Discounts are removed so that pre-discount totals can be calculated in the next step
  • CalculateTotalsActivity
  • CalculateDiscountsActivity
  • CalculateTotalsActivity. A second calculation of totals that includes discounts
  • RecordPromotionUsageActivity

CartPrepareActivityFlow

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
  • CheckInventoryActivity
  • ShipmentSplitActivity
  • ProcessShipmentsActivity
  • RemoveDiscountsActivity. Discounts are removed so that pre-discount and pre-tax totals can be calculated in the next step
  • CalculateTotalsActivity
  • CalculateDiscountsActivity
  • CalculateTaxActivity
  • CalculateTotalsActivity. This second calculation of totals includes discounts and taxes
  • RecordPromotionUsageActivity

CartCheckoutActivityFlow

Validates order total, process 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
  • CalculateTotalsActivity
  • AdjustInventoryActivity
  • RecordPromotionUsageActivity

Activities

  • 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 the Taxes section.
  • 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.
  • ProcessShipmentsActivity. Determines an order's shipping rates by calling the GetRate method associated with each shipment of a cart's line items.
  • 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 an error message if a line item price changed or if the quantity of a line item is reduced due to an inventory shortage, and removes SKUs (with an error message returned) that are no longer active, or are members of inactive catalogs.

Procedure

  • Activity flows are executed using the CartHelper.RunWorkflow() method.
  • 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 Customizing Order Processing Activity Flows.

Last updated: Oct 12, 2015