Back to blog
Guides·Published onSep 25, 2025

Feature Recipe: Pre-Orders

HAS
Housein Abo ShaarGrowth Engineer & Developer Advocate, Vendure
A guide to building a Vendure plugin that automates pre-order fulfillment using the EventBus and Job Queues for reliable, event-driven background processing.

Vendure's stock control system provides the basis for pre-orders by allowing back-ordering via a negative outOfStockThreshold.

This guide shows how to build upon that feature with a plugin that fully automates the pre-order workflow.

The plugin will automatically create fulfillments for outstanding orders as soon as new inventory is added.

The plugin demonstrates core Vendure concepts, including using the EventBus for stock movement detection, the JobQueueService for reliable background processing, and a dedicated service for handling complex order fulfillment logic.

1. Plugin Architecture: Listening for Stock Changes

The plugin's entry point sets up the core event-driven logic. It uses the onModuleInit lifecycle hook to perform two key actions: creating a job queue and subscribing to stock events.

We first use the Vendure CLI to scaffold our plugin:

Then, we create a Job Queue named process-preorders.

This queue handles fulfillment processing asynchronously in the background.

The process function delegates the actual work to our PreOrderService.

File: src/plugins/pre-order/pre-order.plugin.ts

Next, we subscribe to the StockMovementEvent on the EventBus.

This allows the plugin to react whenever inventory levels change.

When stock is added (an ADJUSTMENT movement with a positive quantity), we add a new job to the queue for the relevant product variant.

2. Service Logic: Finding and Processing Orders

The PreOrderService contains the core business logic.

When a job is processed, it first checks the current stock levels.

The critical trigger condition is that there must be both stockOnHand (physical inventory) and stockAllocated (inventory reserved for existing orders).

File: src/plugins/pre-order/services/pre-order.service.ts

Next, the service finds all eligible orders with a state like PaymentSettled or PartiallyShipped. The orders are sorted by their creation date to ensure a fair, First-In-First-Out (FIFO) fulfillment process.

3. Calculating Fulfillment Quantities

To handle partial shipments correctly, the plugin calculates the precise unfulfilled quantity for each order line.

It inspects existing fulfillments to determine how many items have already been shipped, preventing duplicate shipments.

4. Creating the Fulfillment

Finally, the service creates a new fulfillment for the eligible order lines.

It uses the order's original shipping method to maintain consistency with the customer's choice and creates a manual-fulfillment record.

And that is the core logic.

With this plugin active, outstanding pre-orders will now be fulfilled automatically as soon as new stock is registered in the system.

Extending the Logic

This recipe provides a minimal implementation to demonstrate the core concepts. Here are a couple of ways you could build upon this foundation using other Vendure features:

  • Customer Notifications: Use Vendure's EmailPlugin to automatically send an email to the customer when their pre-order fulfillment is created. You could listen for the FulfillmentEvent and trigger a custom email template. You can learn more about how to set this up in the email documentation.
  • Explicit Pre-Order Flag: Instead of relying solely on the outOfStockThreshold, you could add a boolean custom field named "isPreOrder" to the ProductVariant. This allows you to explicitly control which products are available for pre-order, and the flag can be used by your storefront to display a "Pre-Order" button.

Further Reading

Share this article