createPromotions - Promotion Module Reference

This documentation provides a reference to the createPromotions method. This belongs to the Promotion Module.

Note: You should only use this methods when implementing complex customizations. For common cases, check out available workflows instead.

createPromotions(data, sharedContext?): Promise<PromotionDTO[]>#

This method creates promotions.

Example#

Code
1const promotions = await promotionModuleService.createPromotions([2  {3    code: "50OFF",4    type: "standard",5    status: "active",6    application_method: {7      type: "percentage",8      target_type: "items",9      value: 50,10    },11  },12  {13    code: "FREESHIPPING",14    type: "standard",15    status: "active",16    application_method: {17      type: "percentage",18      target_type: "shipping_methods",19      value: 100,20    },21  },22  {23    code: "BUY2GET1",24    type: "buyget",25    status: "active",26    application_method: {27      type: "fixed",28      target_type: "items",29      buy_rules_min_quantity: 2,30      apply_to_quantity: 1,31      buy_rules: [32        {33          attribute: "SKU",34          operator: "eq",35          values: ["SHIRT"],36        },37      ],38    },39  },40])

Parameters#

The promotions to be created.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PromotionDTO[]>
The created promotions.

createPromotions(data, sharedContext?): Promise<PromotionDTO>#

This method creates a promotion.

Example#

Code
1const promotionA = await promotionModuleService.createPromotions({2  code: "50OFF",3  type: "standard",4  status: "active",5  application_method: {6    type: "percentage",7    target_type: "items",8    value: 50,9  },10})11
12const promotionB = await promotionModuleService.createPromotions({13  code: "FREESHIPPING",14  type: "standard",15  status: "active",16  application_method: {17    type: "percentage",18    target_type: "shipping_methods",19    value: 100,20  },21})22
23const promotionC = await promotionModuleService.createPromotions({24  code: "BUY2GET1",25  type: "buyget",26  status: "active",27  application_method: {28    type: "fixed",29    target_type: "items",30    buy_rules_min_quantity: 2,31    apply_to_quantity: 1,32    buy_rules: [33      {34        attribute: "SKU",35        operator: "eq",36        values: ["SHIRT"],37      },38    ],39  },40})

Parameters#

The promotion to be created.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PromotionDTO>
The created promotion.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break