OrderOptions

OrderOptions

OrderOptions

Signature

interface OrderOptions {
  orderItemsLimit?: number;
  priceCalculationStrategy?: PriceCalculationStrategy;
  process?: OrderProcessOptions<string>;
  mergeStrategy?: OrderMergeStrategy;
  checkoutMergeStrategy?: OrderMergeStrategy;
  generateOrderCode?: (ctx: RequestContext) => string | Promise<string>;
}

Members

orderItemsLimit

property
type:
number
default:
999

The maximum number of individual items allowed in a single order. This option exists to prevent excessive resource usage when dealing with very large orders. For example, if an order contains a million items, then any operations on that order (modifying a quantity, adding or removing an item) will require Vendure to loop through all million items to perform price calculations against active promotions and taxes. This can have a significant performance impact for very large values.

Attempting to exceed this limit will cause Vendure to throw a OrderItemsLimitError.

priceCalculationStrategy

Defines the logic used to calculate the unit price of an OrderItem when adding an item to an Order.

process

property
type:
OrderProcessOptions<string>
Defines custom states and transition logic for the order process state machine.

mergeStrategy

property
Defines the strategy used to merge a guest Order and an existing Order when signing in.

checkoutMergeStrategy

property
default:
UseGuestStrategy
Defines the strategy used to merge a guest Order and an existing Order when signing in as part of the checkout flow.

generateOrderCode

property
type:
(ctx: RequestContext) => string | Promise<string>

Allows a user-defined function to create Order codes. This can be useful when integrating with existing systems. By default, Vendure will generate a 16-character alphanumeric string.

Note: when using a custom function for Order codes, bear in mind the database limit for string types (e.g. 255 chars for a varchar field in MySQL), and also the need for codes to be unique.

OrderProcessOptions

Defines custom states and transition logic for the order process state machine.

Signature

interface OrderProcessOptions<T extends string> {
  transitions?: Partial<Transitions<T | OrderState>>;
  onTransitionStart?(
        fromState: T,
        toState: T,
        data: { order: Order },
    ): boolean | Promise<boolean> | Observable<boolean> | void;
  onTransitionEnd?(fromState: T, toState: T, data: { order: Order }): void;
  onTransitionError?(fromState: T, toState: T, message?: string): void;
}

Members

transitions

property
type:
Partial<Transitions<T | OrderState>>
Define how the custom states fit in with the default order state transitions.

onTransitionStart

method
type:
(fromState: T, toState: T, data: { order: Order }) => boolean | Promise<boolean> | Observable<boolean> | void
Define logic to run before a state tranition takes place. Returning false will prevent the transition from going ahead.

onTransitionEnd

method
type:
(fromState: T, toState: T, data: { order: Order }) => void
Define logic to run after a state transition has taken place.

onTransitionError

method
type:
(fromState: T, toState: T, message?: string) => void
Define a custom error handler function for transition errors.