ActiveOrderStrategy
This strategy is used to determine the active Order for all order-related operations in
the Shop API. By default, all the Shop API operations that relate to the active Order (e.g.
activeOrder, addItemToOrder, applyCouponCode etc.) will implicitly create a new Order
and set it on the current Session, and then read the session to obtain the active Order.
This behaviour is defined by the DefaultActiveOrderStrategy.
The InputType generic argument should correspond to the input type defined by the
defineInputType() method.
When defineInputType() is used, then the following Shop API operations will receive an additional
activeOrderInput argument allowing the active order input to be specified:
activeOrdereligibleShippingMethodseligiblePaymentMethodsnextOrderStatesaddItemToOrderadjustOrderLineremoveOrderLineremoveAllOrderLinesapplyCouponCoderemoveCouponCodeaddPaymentToOrdersetCustomerForOrdersetOrderShippingAddresssetOrderBillingAddresssetOrderShippingMethodsetOrderCustomFieldstransitionOrderToState
Example
Example
- Extends:
InjectableStrategy
name
stringThe name of the strategy, e.g. "orderByToken", which will also be used as the field name in the ActiveOrderInput type.
defineInputType
() => DocumentNodeDefines the type of the GraphQL Input object expected by the activeOrderInput
input argument.
Example
For example, given the following:
assuming the strategy name is "orderByToken", then the resulting call to activeOrder (or any of the other
affected Shop API operations) would look like:
Note: if more than one graphql input type is being defined (as in a nested input type), then
the first input will be assumed to be the top-level input.
createActiveOrder
(ctx: RequestContext, input: InputType) => Promise<Order>Certain mutations such as addItemToOrder can automatically create a new Order if one does not exist.
In these cases, this method will be called to create the new Order.
If automatic creation of an Order does not make sense in your strategy, then leave this method undefined. You'll then need to take care of creating an order manually by defining a custom mutation.
determineActiveOrder
(ctx: RequestContext, input: InputType) => Promise<Order | undefined>This method is used to determine the active Order based on the current RequestContext in addition to any
input values provided, as defined by the defineInputType method of this strategy.
Note that this method is invoked frequently, so you should aim to keep it efficient. The returned Order, for example, does not need to have its various relations joined.