Skip to main content

Promotion Condition

PromotionCondition

PromotionConditions are used to create Promotions. The purpose of a PromotionCondition is to check the order against a particular predicate function (the check function) and to return true if the Order satisfies the condition, or false if it does not.

Signature
class PromotionCondition<T extends ConfigArgs = ConfigArgs, C extends string = string, R extends CheckPromotionConditionResult = any> extends ConfigurableOperationDef<T> {
readonly priorityValue: number;
code: C
constructor(config: PromotionConditionConfig<T, C, R>)
check(ctx: RequestContext, order: Order, args: ConfigArg[], promotion: Promotion) => Promise<R>;
}

priorityValue

property
number
default:
0

Used to determine the order of application of multiple Promotions on the same Order. See the Promotion priorityScore field for more information.

code

property
C

constructor

method
(config: PromotionConditionConfig<T, C, R>) => PromotionCondition

check

method
(ctx: RequestContext, order: Order, args: ConfigArg[], promotion: Promotion) => Promise<R>

This is the function which contains the conditional logic to decide whether a Promotion should apply to an Order. See CheckPromotionConditionFn.

PromotionConditionConfig

This object is used to configure a PromotionCondition.

Signature
interface PromotionConditionConfig<T extends ConfigArgs, C extends string, R extends CheckPromotionConditionResult> extends ConfigurableOperationDefOptions<T> {
code: C;
check: CheckPromotionConditionFn<T, R>;
priorityValue?: number;
}

code

property
C

check

priorityValue

property
number

CheckPromotionConditionFn

A function which checks whether or not a given Order satisfies the PromotionCondition.

The function should return either a boolean or and plain object type:

  • false: The condition is not satisfied - do not apply PromotionActions
  • true: The condition is satisfied, apply PromotionActions
  • { [key: string]: any; }: The condition is satisfied, apply PromotionActions and pass this object into the PromotionAction's state argument.
Signature
type CheckPromotionConditionFn<T extends ConfigArgs, R extends CheckPromotionConditionResult> = (
ctx: RequestContext,
order: Order,
args: ConfigArgValues<T>,
promotion: Promotion,
) => R | Promise<R>