Promotion Action

promotion-action

ExecutePromotionItemActionFn

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

Signature

type ExecutePromotionItemActionFn<T extends ConfigArgs> = (
    orderItem: OrderItem,
    orderLine: OrderLine,
    args: ConfigArgValues<T>,
) => 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> = (
    order: Order,
    args: ConfigArgValues<T>,
) => number | Promise<number>

PromotionItemActionConfig

undefined

Signature

interface PromotionItemActionConfig<T extends ConfigArgs> extends PromotionActionConfig<T> {
  execute: ExecutePromotionItemActionFn<T>;
}

Extends

  • PromotionActionConfig<T>

Members

execute

property
The function which contains the promotion calculation logic.

PromotionOrderActionConfig

undefined

Signature

interface PromotionOrderActionConfig<T extends ConfigArgs> extends PromotionActionConfig<T> {
  execute: ExecutePromotionOrderActionFn<T>;
}

Extends

  • PromotionActionConfig<T>

Members

execute

property
The function which contains the promotion calculation logic.

PromotionAction

An abstract class which is extended by PromotionItemAction and PromotionOrderAction.

Signature

class PromotionAction<T extends ConfigArgs = {}> extends ConfigurableOperationDef<T> {
  readonly readonly priorityValue: number;
  constructor(config: PromotionActionConfig<T>)
}

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.

constructor

protected method
type:
(config: PromotionActionConfig<T>) => 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(orderItem, orderLine, args) {
        return -orderLine.unitPrice * (args.discount / 100);
    },
    description: 'Discount every item by { discount }%',
});

Signature

class PromotionItemAction<T extends ConfigArgs = ConfigArgs> extends PromotionAction<T> {
  constructor(config: PromotionItemActionConfig<T>)
}

Extends

Members

constructor

method
type:
(config: PromotionItemActionConfig<T>) => 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(order, args) {
        return -order.subTotal * (args.discount / 100);
    },
    description: 'Discount order by { discount }%',
});

Signature

class PromotionOrderAction<T extends ConfigArgs = ConfigArgs> extends PromotionAction<T> {
  constructor(config: PromotionOrderActionConfig<T>)
}

Extends

Members

constructor

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