Skip to main content

OrderInterceptor

An OrderInterceptor is a class which can be used to intercept and modify the behavior of order-related operations.

It does this by providing methods which are called whenever the contents of an order are about to get changed. These methods are able to prevent the operation from proceeding by returning a string error message.

Examples of use-cases for an OrderInterceptor include:

  • Preventing certain products from being added to the order based on some criteria, e.g. if the product is already in another active order.
  • Enforcing a minimum or maximum quantity of a given product in the order
  • Using a CAPTCHA to prevent automated order creation
Info

This is configured via the orderOptions.orderInterceptors property of your VendureConfig.

OrderInterceptors are executed when the following mutations are called:

  • addItemToOrder
  • adjustOrderLine
  • removeItemFromOrder

Additionally, if you are working directly with the OrderService, the following methods will trigger any registered OrderInterceptors:

  • addItemToOrder
  • addItemsToOrder
  • adjustOrderLine
  • adjustOrderLines
  • removeItemFromOrder
  • removeItemsFromOrder

When an OrderInterceptor is registered, it will be called in the order in which it was registered. If an interceptor method resolves to a string, the operation will be prevented and the string will be used as the error message.

When multiple interceptors are registered, the first interceptor to resolve to a string will prevent the operation from proceeding.

Errors returned by OrderInterceptors are surfaced to the GraphQL API as an OrderInterceptorError and can be queried like this:

Graphql

In the above example, the error message returned by the OrderInterceptor would be available in the interceptorError field.

Example: Min/max order quantity

Let's say we want to allow ProductVariants to specify the minimum or maximum amount which may be added to an order. We can define custom fields to store this information and then use this custom field value to prevent an order line from being added to the order if the quantity is below the minimum.

Example

Ts
Signature

willAddItemToOrder

method(ctx: RequestContext, order: Order, input: WillAddItemToOrderInput) => Promise<void | string> | void | string

Called when a new item is about to be added to the order, as in the addItemToOrder mutation or the addItemToOrder() / addItemsToOrder() method of the OrderService.

willAdjustOrderLine

method(ctx: RequestContext, order: Order, input: WillAdjustOrderLineInput) => Promise<void | string> | void | string

Called when an existing order line is about to be adjusted, as in the adjustOrderLine mutation or the adjustOrderLine() / adjustOrderLines() method of the OrderService.

willRemoveItemFromOrder

method(ctx: RequestContext, order: Order, orderLine: OrderLine) => Promise<void | string> | void | string

Called when an item is about to be removed from the order, as in the removeItemFromOrder mutation or the removeItemFromOrder() / removeItemsFromOrder() method of the OrderService.

Was this chapter helpful?
Report Issue
Edited Feb 23, 2026ยทEdit this page