title | isDefaultIndex | generated |
---|---|---|
OrderProcess |
false |
true |
import MemberInfo from '@site/src/components/MemberInfo'; import GenerationInfo from '@site/src/components/GenerationInfo'; import MemberDescription from '@site/src/components/MemberDescription';
An OrderProcess is used to define the way the order process works as in: what states an Order can be
in, and how it may transition from one state to another. Using the onTransitionStart()
hook, an
OrderProcess can perform checks before allowing a state transition to occur, and the onTransitionEnd()
hook allows logic to be executed after a state change.
For detailed description of the interface members, see the StateMachineConfig docs.
:::info
This is configured via the orderOptions.process
property of
your VendureConfig.
:::
interface OrderProcess<State extends keyof CustomOrderStates | string> extends InjectableStrategy {
transitions?: Transitions<State, State | OrderState> & Partial<Transitions<OrderState | State>>;
onTransitionStart?: OnTransitionStartFn<State | OrderState, OrderTransitionData>;
onTransitionEnd?: OnTransitionEndFn<State | OrderState, OrderTransitionData>;
onTransitionError?: OnTransitionErrorFn<State | OrderState>;
}
- Extends:
InjectableStrategy
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/transitions#transitions'>Transitions</a><State, State | <a href='/reference/typescript-api/orders/order-process#orderstate'>OrderState</a>> & Partial<<a href='/reference/typescript-api/state-machine/transitions#transitions'>Transitions</a><<a href='/reference/typescript-api/orders/order-process#orderstate'>OrderState</a> | State>>
} />
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionstartfn'>OnTransitionStartFn</a><State | <a href='/reference/typescript-api/orders/order-process#orderstate'>OrderState</a>, <a href='/reference/typescript-api/orders/order-process#ordertransitiondata'>OrderTransitionData</a>>
} />
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionendfn'>OnTransitionEndFn</a><State | <a href='/reference/typescript-api/orders/order-process#orderstate'>OrderState</a>, <a href='/reference/typescript-api/orders/order-process#ordertransitiondata'>OrderTransitionData</a>>
} />
<MemberInfo kind="property" type={<a href='/reference/typescript-api/state-machine/state-machine-config#ontransitionerrorfn'>OnTransitionErrorFn</a><State | <a href='/reference/typescript-api/orders/order-process#orderstate'>OrderState</a>>
} />
Options which can be passed to the configureDefaultOrderProcess function
to configure an instance of the default OrderProcess. By default, all
options are set to true
.
interface DefaultOrderProcessOptions {
checkModificationPayments?: boolean;
checkAdditionalPaymentsAmount?: boolean;
checkAllVariantsExist?: boolean;
arrangingPaymentRequiresContents?: boolean;
arrangingPaymentRequiresCustomer?: boolean;
arrangingPaymentRequiresShipping?: boolean;
arrangingPaymentRequiresStock?: boolean;
checkPaymentsCoverTotal?: boolean;
checkAllItemsBeforeCancel?: boolean;
checkFulfillmentStates?: boolean;
}
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents an Order from transitioning out of the Modifying
state if
the Order price has changed and there is no Payment or Refund associated
with the Modification.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents an Order from transitioning out of the ArrangingAdditionalPayment
state if
the Order's Payments do not cover the full amount of totalWithTax
.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents the transition from AddingItems
to any other state (apart from Cancelled
) if
and of the ProductVariants no longer exists due to deletion.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the ArrangingPayment
state if the active Order has no lines.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the ArrangingPayment
state if the active Order has no customer
associated with it.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the ArrangingPayment
state if the active Order has no shipping
method set.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the ArrangingPayment
state if there is insufficient saleable
stock to cover the contents of the Order.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the PaymentAuthorized
or PaymentSettled
states if the order
totalWithTax
amount is not covered by Payment(s) in the corresponding states.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the Cancelled
state unless all OrderItems are already
cancelled.
<MemberInfo kind="property" type={boolean
} default="true" />
Prevents transition to the Shipped
, PartiallyShipped
, Delivered
& PartiallyDelivered
states unless
there are corresponding Fulfillments in the correct states to allow this. E.g. Shipped
only if all items in
the Order are part of a Fulfillment which itself is in the Shipped
state.
Used to configure a customized instance of the default OrderProcess that ships with Vendure. Using this function allows you to turn off certain checks and constraints that are enabled by default.
import { configureDefaultOrderProcess, VendureConfig } from '@vendure/core';
const myCustomOrderProcess = configureDefaultOrderProcess({
// Disable the constraint that requires
// Orders to have a shipping method assigned
// before payment.
arrangingPaymentRequiresShipping: false,
});
export const config: VendureConfig = {
orderOptions: {
process: [myCustomOrderProcess],
},
};
The DefaultOrderProcessOptions type defines all available options. If you require even more customization, you can create your own implementation of the OrderProcess interface.
function configureDefaultOrderProcess(options: DefaultOrderProcessOptions): void
Parameters
<MemberInfo kind="parameter" type={<a href='/reference/typescript-api/orders/order-process#defaultorderprocessoptions'>DefaultOrderProcessOptions</a>
} />
This is the built-in OrderProcess that ships with Vendure. A customized version of this process can be created using the configureDefaultOrderProcess function, which allows you to pass in an object to enable/disable certain checks.
An interface to extend the OrderState type.
interface OrderStates {
}
These are the default states of the Order process. They can be augmented and
modified by using the OrderOptions process
property, and by default
the defaultOrderProcess will add the states
ArrangingPayment
PaymentAuthorized
PaymentSettled
PartiallyShipped
Shipped
PartiallyDelivered
Delivered
Modifying
ArrangingAdditionalPayment
type OrderState = | 'Created'
| 'Draft'
| 'AddingItems'
| 'Cancelled'
| keyof CustomOrderStates
| keyof OrderStates
This is the object passed to the OrderProcess state transition hooks.
interface OrderTransitionData {
ctx: RequestContext;
order: Order;
}