OnOrderValidate
This hook runs immediately after the OnOrderCalculate hook — which itself runs after OnOrderPlan and OnOrderCommands — and any commands those hooks returned have been applied to the Order Actor.
It is the place to enforce invariants that can only be checked once all OnOrderCommands, OnOrderPlan and OnOrderCalculate rules have settled, and to either reject the order with a validationError effect or auto-fix it by emitting more orderCommand effects.
Commands returned from this hook are applied to the order, but do not re-trigger OnOrderCommands, OnOrderPlan, OnOrderCalculate or OnOrderValidate. The hook runs once per message.
Type
{
hook: 'OnOrderValidate'
before: Order // The order before the incoming message commands were applied
order: Order // The order after OnOrderCalculate has run
isPreview: bool // true when the order is evaluated as part of a preview render
}isPreview
The order pipeline also runs inside preview renders — for example, every cart render preview-completes the ticket through the full order pipeline, and the result is rolled back afterwards. isPreview tells a rule which of the two it is looking at: true during a preview render, false for a real mutation that persists.
Rules should generally not branch on preview state — validation is the one accepted exception. The field exists so a validation rule can, for example, allow more lenient validation to allow preview of an otherwise bad state.
Effects
validationError
Reverts the order state and returns the error to the caller. messageActor
Sends a message to another actor. Responses are ignored. scheduleJob
Schedules a job. sendEmail
Queues an email for delivery through the Sendings system. orderCommand
Applies a corrective command to the order. Commands returned from OnOrderValidate do not re-trigger OnOrderCommands or OnOrderValidate.