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    application_method: {6      type: "percentage",7      target_type: "items",8      value: 50,9    },10  },11  {12    code: "FREESHIPPING",13    type: "standard",14    application_method: {15      type: "percentage",16      target_type: "shipping_methods",17      value: 100,18    },19  },20  {21    code: "BUY2GET1",22    type: "buyget",23    application_method: {24      type: "fixed",25      target_type: "items",26      buy_rules_min_quantity: 2,27      apply_to_quantity: 1,28      buy_rules: [29        {30          attribute: "SKU",31          operator: "eq",32          values: ["SHIRT"],33        },34      ],35    },36  },37])

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

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