Ucommerce
  • Ucommerce Next Gen
    • Getting Started
      • Prerequisites
      • Licensing
      • Ucommerce Templates
      • Headless Template
      • MVC Template
    • Headless
      • Postman Collection
      • Headless API Authentication
        • Token endpoint - Authorization Header
        • Authorization Scopes
        • Refreshing the Access Token
      • Reference
        • Cart
        • Cart / Order Line Items
        • Shipment
        • Billing
        • Promotion Codes
        • Price Groups
        • Payment Methods
        • Countries
        • Shipping Methods
        • Catalogs
        • Cart Custom Properties
        • Line Item Custom Properties
        • Orders
        • Views for Cart modifying operations
      • Custom Headless APIs
      • Error Handling
      • Pagination
      • Deprecation
    • Backoffice Authentication
      • Microsoft Entra ID Example
      • Auth0 Authentication Example
    • Definitions
      • What is a Definition
    • Search and indexing
      • Configuration
      • Indexing
        • Index Definitions
        • Facets
        • Indexing Prices
        • Suggestions
        • Custom Data
      • Searching
    • Payment Providers
      • Stripe Provider Integration
      • Implementing a custom payment provider
    • Data Import
    • Miscellaneous
      • Media
      • Price Group Inheritance
      • Price Group Criteria
      • Soft Deletion Of Entities
      • Logging
      • OpenTelemetry
    • Extensions
      • Extending Pipelines
        • Order Processing Pipelines
        • Checkout Pipelines
      • Changing Service Behavior
        • Images
        • Content
      • Custom Headless APIs
      • Extend the Backoffice
        • Custom UI Components
      • Custom Editor UI
      • Custom Promotion Criteria
      • Custom Price Group Criteria
    • How-To
      • Migrate from Classic
        • Common database issues
      • Entities from code
        • Bootstrapping data on startup
        • Product Definitions & Fields
      • Discover pipelines and their tasks
      • Executing a pipeline
    • Integrations
      • Umbraco Media Delivery API
      • App Slices
        • Product Picker
  • Release Notes
  • Contact Us
Powered by GitBook
On this page
  • Implementing a Task
  • Adding a Task
  • Use the extension method to register tasks

Was this helpful?

  1. Ucommerce Next Gen
  2. Extensions
  3. Extending Pipelines

Order Processing Pipelines

PreviousExtending PipelinesNextCheckout Pipelines

Last updated 1 year ago

Was this helpful?

Order processing pipelines are workflows executed automatically when an order moves from one status to another. When an order status changes, the pipeline associated with the new status is executed and can be customized for business logic and integrations.

The way to customize the order processing pipelines differs slightly from regular pipelines. It happens on a dedicated pipeline builder and requires an alias identifier for each pipeline.

Ucommerce comes with the following order processing pipelines out of the box:

Pipeline Alias
Order Status Trigger

ToCompletedOrder

Order set as completed

ToCancelled

Order set as cancelled

Implementing a Task

Tasks are implemented in the same way as other pipelines in Ucommerce by creating a new class that inherits from the interface IPipelineTask<OrderProcessingInput, OrderProcessingOutput>. See for details.

public class MyCustomOrderProcessingTask : IPipelineTask<OrderProcessingInput, OrderProcessingOutput>
{
    public CascadeMode CascadeMode => CascadeMode.Continue;

    public Task Execute(PipelineContext<OrderProcessingInput, OrderProcessingOutput> context, CancellationToken cancellationToken)
    {
        // Your custom logic.
    }
}

Adding a Task

Adding a task is done through the PaymentBuilder returned by the AddPayments extension method on IUcommerceBuilder. It is recommended that you create an extension method to add your configuration.

public static class CheckoutPipelineExtensions
{
    public static PaymentBuilder AddMyOrderProcessingExtensions(this PaymentBuilder builder)
    {
        //This will insert the task 'MyCustomOrderProcessingTask' just before 'DefaultToCompletedPipelineTask'
        builder
            .OrderProcessingPipelines
            .GetByAlias("ToCompletedOrder")
            .InsertBefore<MyCustomOrderProcessingTask>(typeof(DefaultToCompletedPipelineTask));

        //This will insert the task 'MyCustomOrderProcessingTask' just after 'DefaultToCompletedPipelineTask'
        builder
            .OrderProcessingPipelines
            .GetByAlias("ToCompletedOrder")
            .InsertAfter<MyCustomOrderProcessingTask>(typeof(DefaultToCompletedPipelineTask));

        //This will insert the task 'MyCustomOrderProcessingTask' as the first task of the pipeline
        builder
            .OrderProcessingPipelines
            .GetByAlias("ToCompletedOrder")
            .InsertFirst<MyCustomOrderProcessingTask>();

        //This will insert the task 'MyCustomOrderProcessingTask' as the last task of the pipeline
        builder
            .OrderProcessingPipelines
            .GetByAlias("ToCompletedOrder")
            .InsertLast<MyCustomOrderProcessingTask>();

        //This will remove the default task 'DefaultToCompletedPipelineTask' from the pipeline
        builder
            .OrderProcessingPipelines
            .GetByAlias("ToCompletedOrder")
            .Remove<DefaultToCompletedPipelineTask>();

        return builder;
    }
}

Replace a task by placing your custom task before or after the default task, then remove the default task.

Use the extension method to register tasks

builder.Services.AddUcommerce(builder.Configuration)
    // ... register other Ucommerce components first
    .AddPayments() // We are extending the PaymentBuilder
    .AddMyOrderProcessingExtensions()
    // ...
    .Build();
Implementing a Task section on the Extending Pipelines page