promotion-action
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(ctx, 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(ctx, 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
PromotionShippingAction
Represents a PromotionAction which applies to the shipping cost of an Order.
Signature
class PromotionShippingAction<T extends ConfigArgs = ConfigArgs> extends PromotionAction<T> {
constructor(config: PromotionShippingActionConfig<T>)
}
Extends
Members
constructor
method
type:
(config: PromotionShippingActionConfig<T>) => PromotionShippingAction
ExecutePromotionItemActionFn
The function which is used by a PromotionItemAction to calculate the discount on the OrderItem.
Signature
type ExecutePromotionItemActionFn<T extends ConfigArgs> = (
ctx: RequestContext,
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> = (
ctx: RequestContext,
order: Order,
args: ConfigArgValues<T>,
) => 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> = (
ctx: RequestContext,
shippingLine: ShippingLine,
order: Order,
args: ConfigArgValues<T>,
) => number | Promise<number>
PromotionItemActionConfig
Configuration for a PromotionItemAction
Signature
interface PromotionItemActionConfig<T extends ConfigArgs> extends PromotionActionConfig<T> {
execute: ExecutePromotionItemActionFn<T>;
}
Extends
- PromotionActionConfig<T>
Members
execute
property
type:
ExecutePromotionItemActionFn<T>
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
type:
ExecutePromotionOrderActionFn<T>
The function which contains the promotion calculation logic.
PromotionShippingActionConfig
undefined
Signature
interface PromotionShippingActionConfig<T extends ConfigArgs> extends PromotionActionConfig<T> {
execute: ExecutePromotionShippingActionFn<T>;
}
Extends
- PromotionActionConfig<T>
Members
execute
property
type:
ExecutePromotionShippingActionFn<T>
The function which contains the promotion calculation logic.