addPrices - Pricing Module Reference
BetaThis documentation provides a reference to the addPrices method. This belongs to the Pricing Module.
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:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addPricesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.addPrices({
priceSetId,
prices: [
{
amount: 500,
currency_code: "USD",
rules: {},
},
],
})
// do something with the price set or return it
}
To add prices with rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addPricesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.addPrices({
priceSetId,
prices: [
{
amount: 300,
currency_code: "EUR",
rules: {
region_id: "PL",
city: "krakow"
},
},
{
amount: 400,
currency_code: "EUR",
min_quantity: 0,
max_quantity: 4,
rules: {
region_id: "PL"
},
},
{
amount: 450,
currency_code: "EUR",
rules: {
city: "krakow"
},
}
],
})
// do something with the price set or return it
}
Parameters
The data defining the price set to add the prices to, along with the prices to add.
sharedContextContextA context used to share resources, such as transaction manager, between the application and the module.
sharedContextContextReturns
The price set that the prices were added to.
addPrices(data, sharedContext?): Promise<PriceSetDTO[]>
This method adds prices to multiple price sets.
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:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addPricesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.addPrices([{
priceSetId,
prices: [
{
amount: 500,
currency_code: "USD",
rules: {},
},
],
}])
// do something with the price sets or return them
}
To add prices with rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addPricesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.addPrices([{
priceSetId,
prices: [
{
amount: 300,
currency_code: "EUR",
rules: {
region_id: "PL",
city: "krakow"
},
},
{
amount: 400,
currency_code: "EUR",
min_quantity: 0,
max_quantity: 4,
rules: {
region_id: "PL"
},
},
{
amount: 450,
currency_code: "EUR",
rules: {
city: "krakow"
},
}
],
}])
// do something with the price sets or return them
}
Parameters
The data defining the prices to add per price set.
sharedContextContextA context used to share resources, such as transaction manager, between the application and the module.
sharedContextContextReturns
The list of the price sets that prices were added to.
Was this section helpful?