🚨 Announcing Vendure v2 Beta

Promotion

Promotion

A Promotion is used to define a set of conditions under which promotions actions (typically discounts) will be applied to an Order.

Each assigned PromotionCondition is checked against the Order, and if they all return true, then each assign PromotionItemAction / PromotionOrderAction is applied to the Order.

Signature

class Promotion extends AdjustmentSource implements ChannelAware, SoftDeletable, HasCustomFields {
  type = AdjustmentType.PROMOTION;
  constructor(input?: DeepPartial<Promotion> & {
            promotionConditions?: Array<PromotionCondition<any>>;
            promotionActions?: Array<PromotionAction<any>>;
        })
  @Column({ type: Date, nullable: true })
    deletedAt: Date | null;
  @Column({ type: Date, nullable: true })
    startsAt: Date | null;
  @Column({ type: Date, nullable: true })
    endsAt: Date | null;
  @Column({ nullable: true })
    couponCode: string;
  @Column({ nullable: true })
    perCustomerUsageLimit: number;
  @Column() name: string;
  @Column() enabled: boolean;
  @ManyToMany(type => Channel)
    @JoinTable()
    channels: Channel[];
  @Column(type => CustomPromotionFields)
    customFields: CustomPromotionFields;
  @Column('simple-json') conditions: ConfigurableOperation[];
  @Column('simple-json') actions: ConfigurableOperation[];
  @Column() priorityScore: number;
  async apply(ctx: RequestContext, args: ApplyOrderActionArgs | ApplyOrderItemActionArgs | ApplyShippingActionArgs, state?: PromotionState) => Promise<Adjustment | undefined>;
  async test(ctx: RequestContext, order: Order) => Promise<PromotionTestResult>;
  async activate(ctx: RequestContext, order: Order) => ;
  async deactivate(ctx: RequestContext, order: Order) => ;
}

Extends

  • AdjustmentSource

Implements

Members

type

property
type:

constructor

method
type:
(input?: DeepPartial<Promotion> & { promotionConditions?: Array<PromotionCondition<any>>; promotionActions?: Array<PromotionAction<any>>; }) => Promotion

deletedAt

property
type:
Date | null

startsAt

property
type:
Date | null

endsAt

property
type:
Date | null

couponCode

property
type:
string

perCustomerUsageLimit

property
type:
number

name

property
type:
string

enabled

property
type:
boolean

channels

property
type:
Channel[]

customFields

property
type:
CustomPromotionFields

conditions

property
type:
ConfigurableOperation[]

actions

property
type:
ConfigurableOperation[]

priorityScore

property
type:
number

The PriorityScore is used to determine the sequence in which multiple promotions are tested on a given order. A higher number moves the Promotion towards the end of the sequence.

The score is derived from the sum of the priorityValues of the PromotionConditions and PromotionActions comprising this Promotion.

An example illustrating the need for a priority is this:

Consider 2 Promotions, 1) buy 1 get one free and 2) 10% off when order total is over $50. If Promotion 2 is evaluated prior to Promotion 1, then it can trigger the 10% discount even if the subsequent application of Promotion 1 brings the order total down to way below $50.

apply

async method
type:
(ctx: RequestContext, args: ApplyOrderActionArgs | ApplyOrderItemActionArgs | ApplyShippingActionArgs, state?: PromotionState) => Promise<Adjustment | undefined>

test

async method
type:
(ctx: RequestContext, order: Order) => Promise<PromotionTestResult>

activate

async method
type:
(ctx: RequestContext, order: Order) =>

deactivate

async method
type:
(ctx: RequestContext, order: Order) =>