Skip to main content
Skip to main content

addPrices - Pricing Module Reference

Beta

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

**addPrices**(data, sharedContext?): Promise<[PriceSetDTO](/references/pricing/interfaces/pricing.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

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

Returns

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

**addPrices**(data, sharedContext?): Promise&#60;[PriceSetDTO](/references/pricing/interfaces/pricing.PriceSetDTO)[]&#62;

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

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

Returns

PromisePromise<PriceSetDTO[]>Required
The list of the price sets that prices were added to.
Was this section helpful?