Promotion Action

promotion-action

PromotionAction

An abstract class which is extended by PromotionItemAction, PromotionOrderAction, and PromotionShippingAction.

Signature

class PromotionAction<T extends ConfigArgs = {}, U extends PromotionCondition[] | undefined = any> extends ConfigurableOperationDef<T> {
  readonly readonly priorityValue: number;
  readonly readonly conditions?: U;
  constructor(config: PromotionActionConfig<T, U>)
}

Extends

Members

priorityValue

readonly property
type:
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.

conditions

readonly property
type:
U

constructor

protected method
type:
(config: PromotionActionConfig<T, U>) => PromotionAction

PromotionItemAction

Represents a PromotionAction which applies to individual OrderItems.

Example

// Applies a percentage discount to each OrderItem
const itemPercentageDiscount = new PromotionItemAction({
    code: 'item_percentage_discount',
    args: { discount: 'percentage' },
    execute(ctx, orderItem, orderLine, args) {
        return -orderLine.unitPrice * (args.discount / 100);
    },
    description: 'Discount every item by { discount }%',
});

Signature

class PromotionItemAction<T extends ConfigArgs = ConfigArgs, U extends Array<PromotionCondition<any>> = []> extends PromotionAction<T, U> {
  constructor(config: PromotionItemActionConfig<T, U>)
}

Extends

Members

constructor

method
type:
(config: PromotionItemActionConfig<T, U>) => PromotionItemAction

PromotionOrderAction

Represents a PromotionAction which applies to the Order as a whole.

Example

// Applies a percentage discount to the entire Order
const orderPercentageDiscount = new PromotionOrderAction({
    code: 'order_percentage_discount',
    args: { discount: 'percentage' },
    execute(ctx, order, args) {
        return -order.subTotal * (args.discount / 100);
    },
    description: 'Discount order by { discount }%',
});

Signature

class PromotionOrderAction<T extends ConfigArgs = ConfigArgs, U extends PromotionCondition[] = []> extends PromotionAction<T, U> {
  constructor(config: PromotionOrderActionConfig<T, U>)
}

Extends

Members

constructor

method
type:
(config: PromotionOrderActionConfig<T, U>) => PromotionOrderAction

PromotionShippingAction

Represents a PromotionAction which applies to the shipping cost of an Order.

Signature

class PromotionShippingAction<T extends ConfigArgs = ConfigArgs, U extends PromotionCondition[] = []> extends PromotionAction<T, U> {
  constructor(config: PromotionShippingActionConfig<T, U>)
}

Extends

Members

constructor

method
type:
(config: PromotionShippingActionConfig<T, U>) => PromotionShippingAction

ExecutePromotionItemActionFn

The function which is used by a PromotionItemAction to calculate the discount on the OrderItem.

Signature

type ExecutePromotionItemActionFn<T extends ConfigArgs, U extends Array<PromotionCondition<any>>> = (
    ctx: RequestContext,
    orderItem: OrderItem,
    orderLine: OrderLine,
    args: ConfigArgValues<T>,
    state: ConditionState<U>,
) => number | Promise<number>

ExecutePromotionOrderActionFn

The function which is used by a PromotionOrderAction to calculate the discount on the Order.

Signature

type ExecutePromotionOrderActionFn<T extends ConfigArgs, U extends Array<PromotionCondition<any>>> = (
    ctx: RequestContext,
    order: Order,
    args: ConfigArgValues<T>,
    state: ConditionState<U>,
) => number | Promise<number>

ExecutePromotionShippingActionFn

The function which is used by a PromotionOrderAction to calculate the discount on the Order.

Signature

type ExecutePromotionShippingActionFn<T extends ConfigArgs, U extends Array<PromotionCondition<any>>> = (
    ctx: RequestContext,
    shippingLine: ShippingLine,
    order: Order,
    args: ConfigArgValues<T>,
    state: ConditionState<U>,
) => number | Promise<number>

PromotionActionConfig

Configuration for all types of PromotionAction.

Signature

interface PromotionActionConfig<T extends ConfigArgs, U extends Array<PromotionCondition<any>> | undefined> extends ConfigurableOperationDefOptions<T> {
  priorityValue?: number;
  conditions?: U extends undefined ? undefined : ConditionTuple<Exclude<U, undefined>>;
}

Extends

Members

priorityValue

property
type:
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.

conditions

property
type:
U extends undefined ? undefined : ConditionTuple<Exclude<U, undefined>>

Allows PromotionActions to define one or more PromotionConditions as dependencies. Having a PromotionCondition as a dependency has the following consequences:

  1. A Promotion using this PromotionAction is only valid if it also contains all PromotionConditions on which it depends.
  2. The execute() function will receive a statically-typed state argument which will contain the return values of the PromotionConditions’ check() function.

PromotionItemActionConfig

Configuration for a PromotionItemAction

Signature

interface PromotionItemActionConfig<T extends ConfigArgs, U extends PromotionCondition[]> extends PromotionActionConfig<T, U> {
  execute: ExecutePromotionItemActionFn<T, U>;
}

Extends

Members

execute

property
The function which contains the promotion calculation logic.

PromotionOrderActionConfig

undefined

Signature

interface PromotionOrderActionConfig<T extends ConfigArgs, U extends PromotionCondition[]> extends PromotionActionConfig<T, U> {
  execute: ExecutePromotionOrderActionFn<T, U>;
}

Extends

Members

execute

property
The function which contains the promotion calculation logic.

PromotionShippingActionConfig

undefined

Signature

interface PromotionShippingActionConfig<T extends ConfigArgs, U extends PromotionCondition[]> extends PromotionActionConfig<T, U> {
  execute: ExecutePromotionShippingActionFn<T, U>;
}

Extends

Members

execute

property
The function which contains the promotion calculation logic.