createPriceSets - Pricing Module Reference

This documentation provides a reference to the createPriceSets method. This belongs to the Pricing Module.

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

createPriceSets(data, sharedContext?): Promise<PriceSetDTO>#

This method is used to create a new price set.

Example#

To create a default price set, don't pass any rules. For example:

Code
1const priceSet = await pricingModuleService.createPriceSets({2  rules: [],3  prices: [4    {5      amount: 500,6      currency_code: "USD",7      min_quantity: 0,8      max_quantity: 4,9      rules: {},10    },11    {12      amount: 400,13      currency_code: "USD",14      min_quantity: 5,15      max_quantity: 10,16      rules: {},17    },18  ],19})

To create a price set and associate it with rule types:

Code
1const priceSet = await pricingModuleService.createPriceSets({2  prices: [3    {4      amount: 300,5      currency_code: "EUR",6      rules: {7        region_id: "PL",8        city: "krakow",9      },10    },11    {12      amount: 400,13      currency_code: "EUR",14      rules: {15        region_id: "PL",16      },17    },18    {19      amount: 450,20      currency_code: "EUR",21      rules: {22        city: "krakow",23      },24    },25  ],26})

Parameters#

The attributes of the price set to create.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PriceSetDTO>
The created price set.

createPriceSets(data, sharedContext?): Promise<PriceSetDTO[]>#

This method is used to create multiple price sets.

Example#

Code
1const priceSets = await pricingModuleService.createPriceSets([2  // default price set3  {4    rules: [],5    prices: [6      {7        amount: 500,8        currency_code: "USD",9        min_quantity: 0,10        max_quantity: 4,11        rules: {},12      },13      {14        amount: 400,15        currency_code: "USD",16        min_quantity: 5,17        max_quantity: 10,18        rules: {},19      },20    ],21  },22  // price set with rules23  {24    prices: [25      {26        amount: 300,27        currency_code: "EUR",28        rules: {29          region_id: "PL",30          city: "krakow",31        },32      },33      {34        amount: 400,35        currency_code: "EUR",36        rules: {37          region_id: "PL",38        },39      },40      {41        amount: 450,42        currency_code: "EUR",43        rules: {44          city: "krakow",45        },46      },47    ],48  },49])

Parameters#

The price sets to create.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PriceSetDTO[]>
The list of created price sets.
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