addPrices - Pricing Module Reference

This documentation provides a reference to the addPrices 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.

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

This method adds prices to a price set.

Example#

To add a default price to a price set, don't pass it any rules and make sure to pass it the currency_code:

Code
1const priceSet = await pricingModuleService.addPrices({2  priceSetId: "pset_123",3  prices: [4    {5      amount: 500,6      currency_code: "USD",7      rules: {},8    },9  ],10})

To add prices with rules:

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

Parameters#

The data defining the price set to add the prices to, along with the prices to add.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PriceSetDTO>
The price set that the prices were added to.

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

This method adds prices to multiple price sets.

Example#

Code
1const priceSets = await pricingModuleService.addPrices([2  {3    priceSetId: "pset_123",4    prices: [5      // default price because it doesn't6      // have rules7      {8        amount: 500,9        currency_code: "USD",10        rules: {},11      },12    ],13  },14  {15    priceSetId: "pset_321",16    prices: [17      // prices with rules18      {19        amount: 300,20        currency_code: "EUR",21        rules: {22          region_id: "PL",23          city: "krakow",24        },25      },26    ],27  },28])

Parameters#

The data defining the prices to add per price set.
sharedContextContextOptional
A context used to share resources, such as transaction manager, between the application and the module.

Returns#

PromisePromise<PriceSetDTO[]>
The list of the price sets that prices were added to.
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