IPricingModuleService
Methods
addPrices
**addPrices**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.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
sharedContext
ContextReturns
**addPrices**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.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
sharedContext
ContextReturns
addRules
**addRules**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.PriceSetDTO)>
This method adds rules to a price set.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addRulesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.addRules({
priceSetId,
rules: [{
attribute: "region_id"
}]
})
// do something with the price set or return it
}
Parameters
sharedContext
ContextReturns
**addRules**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.PriceSetDTO)[]>
This method adds rules to multiple price sets.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function addRulesToPriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.addRules([{
priceSetId,
rules: [{
attribute: "region_id"
}]
}])
// do something with the price sets or return them
}
Parameters
sharedContext
ContextReturns
calculatePrices
This method is used to calculate prices based on the provided filters and context.
Example
When you calculate prices, you must at least specify the currency code:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function calculatePrice (priceSetId: string, currencyCode: string) {
const pricingService = await initializePricingModule()
const price = await pricingService.calculatePrices(
{ id: [priceSetId] },
{
context: {
currency_code: currencyCode
}
}
)
// do something with the price or return it
}
To calculate prices for specific minimum and/or maximum quantity:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function calculatePrice (priceSetId: string, currencyCode: string) {
const pricingService = await initializePricingModule()
const price = await pricingService.calculatePrices(
{ id: [priceSetId] },
{
context: {
currency_code: currencyCode,
min_quantity: 4
}
}
)
// do something with the price or return it
}
To calculate prices for custom rule types:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function calculatePrice (priceSetId: string, currencyCode: string) {
const pricingService = await initializePricingModule()
const price = await pricingService.calculatePrices(
{ id: [priceSetId] },
{
context: {
currency_code: currencyCode,
region_id: "US"
}
}
)
// do something with the price or return it
}
Parameters
context
PricingContextsharedContext
ContextReturns
create
**create**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.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:
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createPriceSet() {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.create({
rules: [],
prices: [
{
amount: 500,
currency_code: "USD",
min_quantity: 0,
max_quantity: 4,
rules: {},
},
{
amount: 400,
currency_code: "USD",
min_quantity: 5,
max_quantity: 10,
rules: {},
},
],
})
// do something with the price set or return it
}
To create a price set and associate it with rule types:
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createPriceSet() {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.create({
rules: [{ rule_attribute: "region_id" }, { rule_attribute: "city" }],
prices: [
{
amount: 300,
currency_code: "EUR",
rules: {
region_id: "PL",
city: "krakow",
},
},
{
amount: 400,
currency_code: "EUR",
rules: {
region_id: "PL",
},
},
{
amount: 450,
currency_code: "EUR",
rules: {
city: "krakow",
},
},
],
})
// do something with the price set or return it
}
Parameters
sharedContext
ContextReturns
**create**(data, sharedContext?): Promise<[PriceSetDTO](/references/js-client/PricingTypes/interfaces/internal.internal-1.PricingTypes.PriceSetDTO)[]>
This method is used to create multiple price sets.
Example
To create price sets with a default price, don't pass any rules and make sure to pass the currency_code
of the price. For example:
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createPriceSets() {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.create([
{
rules: [],
prices: [
{
amount: 500,
currency_code: "USD",
rules: {},
},
],
},
])
// do something with the price sets or return them
}
To create price sets and associate them with rule types:
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createPriceSets() {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.create([
{
rules: [{ rule_attribute: "region_id" }, { rule_attribute: "city" }],
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
sharedContext
ContextReturns
createCurrencies
This method is used to create new currencies.
Example
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createCurrencies() {
const pricingService = await initializePricingModule()
const currencies = await pricingService.createCurrencies([
{
code: "USD",
symbol: "$",
symbol_native: "$",
name: "US Dollar",
},
])
// do something with the currencies or return them
}
Parameters
sharedContext
ContextReturns
createMoneyAmounts
This method creates money amounts.
Example
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function retrieveMoneyAmounts() {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.createMoneyAmounts([
{
amount: 500,
currency_code: "USD",
},
{
amount: 400,
currency_code: "USD",
min_quantity: 0,
max_quantity: 4,
},
])
// do something with the money amounts or return them
}
Parameters
sharedContext
ContextReturns
createPriceRules
This method is used to create new price rules based on the provided data.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function createPriceRules (
id: string,
priceSetId: string,
ruleTypeId: string,
value: string,
priceSetMoneyAmountId: string,
priceListId: string
) {
const pricingService = await initializePricingModule()
const priceRules = await pricingService.createPriceRules([
{
id,
price_set_id: priceSetId,
rule_type_id: ruleTypeId,
value,
price_set_money_amount_id: priceSetMoneyAmountId,
price_list_id: priceListId
}
])
// do something with the price rules or return them
}
Parameters
sharedContext
ContextReturns
createPriceSetMoneyAmountRules
This method is used to create new price set money amount rules. A price set money amount rule creates an association between a price set money amount and a rule type.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function createPriceSetMoneyAmountRules (priceSetMoneyAmountId: string, ruleTypeId: string, value: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.createPriceSetMoneyAmountRules([
{
price_set_money_amount: priceSetMoneyAmountId,
rule_type: ruleTypeId,
value
}
])
// do something with the price set money amount rules or return them
}
Parameters
sharedContext
ContextReturns
createRuleTypes
This method is used to create new rule types.
Example
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function createRuleTypes() {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.createRuleTypes([
{
name: "Region",
rule_attribute: "region_id",
},
])
// do something with the rule types or return them
}
Parameters
sharedContext
ContextReturns
delete
This method deletes price sets by their IDs.
Example
Parameters
ids
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteCurrencies
This method is used to delete currencies based on their currency code.
Example
Parameters
currencyCodes
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteMoneyAmounts
This method deletes money amounts by their IDs.
Example
Parameters
ids
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeletePriceRules
This method is used to delete price rules based on the specified IDs.
Example
Parameters
priceRuleIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeletePriceSetMoneyAmountRules
This method is used to delete price set money amount rules based on the specified IDs.
Example
Parameters
ids
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteRuleTypes
This method is used to delete rule types based on the provided IDs.
Example
Parameters
ruleTypeIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>Requiredlist
This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
Example
To retrieve a list of price sets using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[]) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.list(
{
id: priceSetIds
},
)
// do something with the price sets or return them
}
To specify relations that should be retrieved within the price sets:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[]) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.list(
{
id: priceSetIds
},
{
relations: ["money_amounts"]
}
)
// do something with the price sets or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.list(
{
id: priceSetIds
},
{
relations: ["money_amounts"],
skip,
take
}
)
// do something with the price sets or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSets = await pricingService.list(
{
$and: [
{
id: priceSetIds
},
{
money_amounts: {
id: moneyAmountIds
}
}
]
},
{
relations: ["money_amounts"],
skip,
take
}
)
// do something with the price sets or return them
}
Parameters
filters
FilterablePriceSetPropsconfig
FindConfig<PriceSetDTO>select
or relations
, accept the attributes or relations associated with a price set.sharedContext
ContextReturns
listAndCount
This method is used to retrieve a paginated list of price sets along with the total count of available price sets satisfying the provided filters.
Example
To retrieve a list of prices sets using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[]) {
const pricingService = await initializePricingModule()
const [priceSets, count] = await pricingService.listAndCount(
{
id: priceSetIds
},
)
// do something with the price sets or return them
}
To specify relations that should be retrieved within the price sets:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[]) {
const pricingService = await initializePricingModule()
const [priceSets, count] = await pricingService.listAndCount(
{
id: priceSetIds
},
{
relations: ["money_amounts"]
}
)
// do something with the price sets or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSets, count] = await pricingService.listAndCount(
{
id: priceSetIds
},
{
relations: ["money_amounts"],
skip,
take
}
)
// do something with the price sets or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSets (priceSetIds: string[], moneyAmountIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSets, count] = await pricingService.listAndCount(
{
$and: [
{
id: priceSetIds
},
{
money_amounts: {
id: moneyAmountIds
}
}
]
},
{
relations: ["money_amounts"],
skip,
take
}
)
// do something with the price sets or return them
}
Parameters
filters
FilterablePriceSetPropsconfig
FindConfig<PriceSetDTO>select
or relations
, accept the attributes or relations associated with a price set.sharedContext
ContextReturns
listAndCountCurrencies
This method is used to retrieve a paginated list of currencies along with the total count of available currencies satisfying the provided filters.
Example
To retrieve a list of currencies using their codes:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[]) {
const pricingService = await initializePricingModule()
const [currencies, count] = await pricingService.listAndCountCurrencies(
{
code: codes
},
)
// do something with the currencies or return them
}
To specify attributes that should be retrieved within the money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[]) {
const pricingService = await initializePricingModule()
const [currencies, count] = await pricingService.listAndCountCurrencies(
{
code: codes
},
{
select: ["symbol_native"]
}
)
// do something with the currencies or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [currencies, count] = await pricingService.listAndCountCurrencies(
{
code: codes
},
{
select: ["symbol_native"],
skip,
take
}
)
// do something with the currencies or return them
}
Parameters
filters
FilterableCurrencyPropsconfig
FindConfig<CurrencyDTO>select
or relations
, accept the attributes or relations associated with a currency.sharedContext
ContextReturns
listAndCountMoneyAmounts
This method is used to retrieve a paginated list of money amounts along with the total count of available money amounts satisfying the provided filters.
Example
To retrieve a list of money amounts using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
const pricingService = await initializePricingModule()
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
{
id: moneyAmountIds
}
)
// do something with the money amounts or return them
}
To specify relations that should be retrieved within the money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
const pricingService = await initializePricingModule()
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
{
id: moneyAmountIds
},
{
relations: ["currency"]
}
)
// do something with the money amounts or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
{
id: moneyAmountIds
},
{
relations: ["currency"],
skip,
take
}
)
// do something with the money amounts or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [moneyAmounts, count] = await pricingService.listAndCountMoneyAmounts(
{
$and: [
{
id: moneyAmountIds
},
{
currency_code: currencyCode
}
]
},
{
relations: ["currency"],
skip,
take
}
)
// do something with the money amounts or return them
}
Parameters
filters
FilterableMoneyAmountPropsconfig
FindConfig<MoneyAmountDTO>select
or relations
, accept the attributes or relations associated with a money amount.sharedContext
ContextReturns
listAndCountPriceRules
This method is used to retrieve a paginated list of price rules along with the total count of available price rules satisfying the provided filters.
Example
To retrieve a list of price rules using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (id: string) {
const pricingService = await initializePricingModule()
const [priceRules, count] = await pricingService.listAndCountPriceRules({
id: [id]
})
// do something with the price rules or return them
}
To specify relations that should be retrieved within the price rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (id: string) {
const pricingService = await initializePricingModule()
const [priceRules, count] = await pricingService.listAndCountPriceRules({
id: [id],
}, {
relations: ["price_set"]
})
// do something with the price rules or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceRules, count] = await pricingService.listAndCountPriceRules({
id: [id],
}, {
relations: ["price_set"],
skip,
take
})
// do something with the price rules or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceRules, count] = await pricingService.listAndCountPriceRules({
$and: [
{
id: ids
},
{
name
}
]
}, {
relations: ["price_set"],
skip,
take
})
// do something with the price rules or return them
}
Parameters
filters
FilterablePriceRulePropsconfig
FindConfig<PriceRuleDTO>select
or relations
, accept the attributes or relations associated with a price rule.sharedContext
ContextReturns
listAndCountPriceSetMoneyAmountRules
This method is used to retrieve a paginated list of price set money amount rules along with the total count of available price set money amount rules satisfying the provided filters.
Example
To retrieve a list of price set money amounts using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
id: [id]
})
// do something with the price set money amount rules or return them
}
To specify relations that should be retrieved within the price set money amount rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
id: [id]
}, {
relations: ["price_set_money_amount"],
})
// do something with the price set money amount rules or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
id: [id]
}, {
relations: ["price_set_money_amount"],
skip,
take
})
// do something with the price set money amount rules or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmountRules, count] = await pricingService.listAndCountPriceSetMoneyAmountRules({
$and: [
{
id: ids
},
{
rule_type_id: ruleTypeId
}
]
}, {
relations: ["price_set_money_amount"],
skip,
take
})
// do something with the price set money amount rules or return them
}
Parameters
select
or relations
, accept the attributes or relations associated with a price set money amount rule.sharedContext
ContextReturns
listAndCountPriceSetMoneyAmounts
This method is used to retrieve a paginated list of price set money amounts along with the total count of available price set money amounts satisfying the provided filters.
Example
To retrieve a list of price set money amounts using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmounts, count] = await pricingService.listAndCountPriceSetMoneyAmounts({
id: [id]
})
// do something with the price set money amounts or return them
}
To specify relations that should be retrieved within the price set money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmounts, count] = await pricingService.listAndCountPriceSetMoneyAmounts({
id: [id]
}, {
relations: ["price_rules"],
})
// do something with the price set money amounts or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmounts, count] = await pricingService.listAndCountPriceSetMoneyAmounts({
id: [id]
}, {
relations: ["price_rules"],
skip,
take
})
// do something with the price set money amounts or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (ids: string[], titles: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [priceSetMoneyAmounts, count] = await pricingService.listAndCountPriceSetMoneyAmounts({
$and: [
{
id: ids
},
{
title: titles
}
]
}, {
relations: ["price_rules"],
skip,
take
})
// do something with the price set money amounts or return them
}
Parameters
config
FindConfig<PriceSetMoneyAmountDTO>select
or relations
, accept the attributes or relations associated with a price set money amount.sharedContext
ContextReturns
listAndCountRuleTypes
This method is used to retrieve a paginated list of rule types along with the total count of available rule types satisfying the provided filters.
Example
To retrieve a list of rule types using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
})
// do something with the rule types or return them
}
To specify attributes that should be retrieved within the rule types:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"]
})
// do something with the rule types or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const [ruleTypes, count] = await pricingService.listAndCountRuleTypes({
$and: [
{
id: ruleTypeId
},
{
name
}
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
Parameters
filters
FilterableRuleTypePropsconfig
FindConfig<RuleTypeDTO>select
or relations
, accept the attributes or relations associated with a rule type.sharedContext
ContextReturns
listCurrencies
This method is used to retrieve a paginated list of currencies based on optional filters and configuration.
Example
To retrieve a list of currencies using their codes:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[]) {
const pricingService = await initializePricingModule()
const currencies = await pricingService.listCurrencies(
{
code: codes
},
)
// do something with the currencies or return them
}
To specify attributes that should be retrieved within the money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[]) {
const pricingService = await initializePricingModule()
const currencies = await pricingService.listCurrencies(
{
code: codes
},
{
select: ["symbol_native"]
}
)
// do something with the currencies or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrencies (codes: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const currencies = await pricingService.listCurrencies(
{
code: codes
},
{
select: ["symbol_native"],
skip,
take
}
)
// do something with the currencies or return them
}
Parameters
filters
FilterableCurrencyPropsconfig
FindConfig<CurrencyDTO>select
or relations
, accept the attributes or relations associated with a currency.sharedContext
ContextReturns
listMoneyAmounts
This method is used to retrieve a paginated list of money amounts based on optional filters and configuration.
Example
To retrieve a list of money amounts using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.listMoneyAmounts(
{
id: moneyAmountIds
}
)
// do something with the money amounts or return them
}
To specify relations that should be retrieved within the money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[]) {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.listMoneyAmounts(
{
id: moneyAmountIds
},
{
relations: ["currency"]
}
)
// do something with the money amounts or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.listMoneyAmounts(
{
id: moneyAmountIds
},
{
relations: ["currency"],
skip,
take
}
)
// do something with the money amounts or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmounts (moneyAmountIds: string[], currencyCode: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.listMoneyAmounts(
{
$and: [
{
id: moneyAmountIds
},
{
currency_code: currencyCode
}
]
},
{
relations: ["currency"],
skip,
take
}
)
// do something with the money amounts or return them
}
Parameters
filters
FilterableMoneyAmountPropsconfig
FindConfig<MoneyAmountDTO>select
or relations
, accept the attributes or relations associated with a money amount.sharedContext
ContextReturns
listPriceRules
This method is used to retrieve a paginated list of price rules based on optional filters and configuration.
Example
To retrieve a list of price rules using their IDs:
To specify relations that should be retrieved within the price rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (id: string) {
const pricingService = await initializePricingModule()
const priceRules = await pricingService.listPriceRules({
id: [id],
}, {
relations: ["price_set"]
})
// do something with the price rules or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceRules = await pricingService.listPriceRules({
id: [id],
}, {
relations: ["price_set"],
skip,
take
})
// do something with the price rules or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRules (ids: string[], name: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceRules = await pricingService.listPriceRules({
$and: [
{
id: ids
},
{
name
}
]
}, {
relations: ["price_set"],
skip,
take
})
// do something with the price rules or return them
}
Parameters
filters
FilterablePriceRulePropsconfig
FindConfig<PriceRuleDTO>select
or relations
, accept the attributes or relations associated with a price rule.sharedContext
ContextReturns
listPriceSetMoneyAmountRules
This method is used to retrieve a paginated list of price set money amount rules based on optional filters and configuration.
Example
To retrieve a list of price set money amount rules using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
id: [id]
})
// do something with the price set money amount rules or return them
}
To specify relations that should be retrieved within the price set money amount rules:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
id: [id]
}, {
relations: ["price_set_money_amount"]
})
// do something with the price set money amount rules or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
id: [id]
}, {
relations: ["price_set_money_amount"],
skip,
take
})
// do something with the price set money amount rules or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRules (ids: string[], ruleTypeId: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.listPriceSetMoneyAmountRules({
$and: [
{
id: ids
},
{
rule_type_id: ruleTypeId
}
]
}, {
relations: ["price_set_money_amount"],
skip,
take
})
// do something with the price set money amount rules or return them
}
Parameters
select
or relations
, accept the attributes or relations associated with a price set money amount rule.sharedContext
ContextReturns
listPriceSetMoneyAmounts
This method is used to retrieve a paginated list of price set money amounts based on optional filters and configuration.
Example
To retrieve a list of price set money amounts using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmounts = await pricingService.listPriceSetMoneyAmounts({
id: [id]
})
// do something with the price set money amounts or return them
}
To specify relations that should be retrieved within the price set money amounts:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmounts = await pricingService.listPriceSetMoneyAmounts({
id: [id]
}, {
relations: ["price_rules"]
})
// do something with the price set money amounts or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (id: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmounts = await pricingService.listPriceSetMoneyAmounts({
id: [id]
}, {
relations: ["price_rules"],
skip,
take
})
// do something with the price set money amounts or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmounts (ids: string[], titles: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmounts = await pricingService.listPriceSetMoneyAmounts({
$and: [
{
id: ids
},
{
title: titles
}
]
}, {
relations: ["price_rules"],
skip,
take
})
// do something with the price set money amounts or return them
}
Parameters
config
FindConfig<PriceSetMoneyAmountDTO>select
or relations
, accept the attributes or relations associated with a price set money amount.sharedContext
ContextReturns
listRuleTypes
This method is used to retrieve a paginated list of rule types based on optional filters and configuration.
Example
To retrieve a list of rule types using their IDs:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.listRuleTypes({
id: [
ruleTypeId
]
})
// do something with the rule types or return them
}
To specify attributes that should be retrieved within the rule types:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.listRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"]
})
// do something with the rule types or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string, skip: number, take: number) {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.listRuleTypes({
id: [
ruleTypeId
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleTypes (ruleTypeId: string[], name: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.listRuleTypes({
$and: [
{
id: ruleTypeId
},
{
name
}
]
}, {
select: ["name"],
skip,
take
})
// do something with the rule types or return them
}
Parameters
filters
FilterableRuleTypePropsconfig
FindConfig<RuleTypeDTO>select
or relations
, accept the attributes or relations associated with a rule type.sharedContext
ContextReturns
removeRules
This method remove rules from a price set.
Example
Parameters
sharedContext
ContextReturns
Promise
Promise<void>Requiredretrieve
This method is used to retrieves a price set by its ID.
Example
A simple example that retrieves a price set by its ID:
To specify relations that should be retrieved:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.retrieve(
priceSetId,
{
relations: ["money_amounts"]
}
)
// do something with the price set or return it
}
Parameters
id
stringRequiredconfig
FindConfig<PriceSetDTO>select
or relations
, accept the attributes or relations associated with a price set.sharedContext
ContextReturns
retrieveCurrency
This method retrieves a currency by its code and and optionally based on the provided configurations.
Example
A simple example that retrieves a currency by its code:
To specify attributes that should be retrieved:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveCurrency (code: string) {
const pricingService = await initializePricingModule()
const currency = await pricingService.retrieveCurrency(
code,
{
select: ["symbol_native"]
}
)
// do something with the currency or return it
}
Parameters
code
stringRequiredconfig
FindConfig<CurrencyDTO>select
or relations
, accept the attributes or relations associated with a currency.sharedContext
ContextReturns
retrieveMoneyAmount
This method retrieves a money amount by its ID.
Example
To retrieve a money amount by its ID:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmount (moneyAmountId: string) {
const pricingService = await initializePricingModule()
const moneyAmount = await pricingService.retrieveMoneyAmount(
moneyAmountId,
)
// do something with the money amount or return it
}
To retrieve relations along with the money amount:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveMoneyAmount (moneyAmountId: string) {
const pricingService = await initializePricingModule()
const moneyAmount = await pricingService.retrieveMoneyAmount(
moneyAmountId,
{
relations: ["currency"]
}
)
// do something with the money amount or return it
}
Parameters
id
stringRequiredconfig
FindConfig<MoneyAmountDTO>select
or relations
, accept the attributes or relations associated with a money amount.sharedContext
ContextReturns
retrievePriceRule
This method is used to retrieve a price rule by its ID.
Example
A simple example that retrieves a price rule by its ID:
To specify relations that should be retrieved:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceRule (id: string) {
const pricingService = await initializePricingModule()
const priceRule = await pricingService.retrievePriceRule(id, {
relations: ["price_set"]
})
// do something with the price rule or return it
}
Parameters
id
stringRequiredconfig
FindConfig<PriceRuleDTO>select
or relations
, accept the attributes or relations associated with a price rule.sharedContext
ContextReturns
retrievePriceSetMoneyAmountRules
This method is used to a price set money amount rule by its ID based on the provided configuration.
Example
A simple example that retrieves a price set money amount rule by its ID:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRule (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRule = await pricingService.retrievePriceSetMoneyAmountRules(id)
// do something with the price set money amount rule or return it
}
To specify relations that should be retrieved:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSetMoneyAmountRule (id: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRule = await pricingService.retrievePriceSetMoneyAmountRules(id, {
relations: ["price_set_money_amount"]
})
// do something with the price set money amount rule or return it
}
Parameters
id
stringRequiredselect
or relations
, accept the attributes or relations associated with a price set money amount rule.sharedContext
ContextReturns
retrieveRuleType
This method is used to retrieve a rule type by its ID and and optionally based on the provided configurations.
Example
A simple example that retrieves a rule type by its code:
To specify attributes that should be retrieved:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrieveRuleType (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const ruleType = await pricingService.retrieveRuleType(ruleTypeId, {
select: ["name"]
})
// do something with the rule type or return it
}
Parameters
id
stringRequiredconfig
FindConfig<RuleTypeDTO>select
or relations
, accept the attributes or relations associated with a rule type.sharedContext
ContextReturns
updateCurrencies
This method is used to update existing currencies with the provided data. In each currency object, the currency code must be provided to identify which currency to update.
Example
import { initialize as initializePricingModule } from "@medusajs/pricing"
async function updateCurrencies() {
const pricingService = await initializePricingModule()
const currencies = await pricingService.updateCurrencies([
{
code: "USD",
symbol: "$",
},
])
// do something with the currencies or return them
}
Parameters
sharedContext
ContextReturns
updateMoneyAmounts
This method updates existing money amounts.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function updateMoneyAmounts (moneyAmountId: string, amount: number) {
const pricingService = await initializePricingModule()
const moneyAmounts = await pricingService.updateMoneyAmounts([
{
id: moneyAmountId,
amount
}
])
// do something with the money amounts or return them
}
Parameters
sharedContext
ContextReturns
updatePriceRules
This method is used to update price rules, each with their provided data.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function updatePriceRules (
id: string,
priceSetId: string,
) {
const pricingService = await initializePricingModule()
const priceRules = await pricingService.updatePriceRules([
{
id,
price_set_id: priceSetId,
}
])
// do something with the price rules or return them
}
Parameters
sharedContext
ContextReturns
updatePriceSetMoneyAmountRules
This method is used to update price set money amount rules, each with their provided data.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function updatePriceSetMoneyAmountRules (id: string, value: string) {
const pricingService = await initializePricingModule()
const priceSetMoneyAmountRules = await pricingService.updatePriceSetMoneyAmountRules([
{
id,
value
}
])
// do something with the price set money amount rules or return them
}
Parameters
sharedContext
ContextReturns
updateRuleTypes
This method is used to update existing rule types with the provided data.
Example
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function updateRuleTypes (ruleTypeId: string) {
const pricingService = await initializePricingModule()
const ruleTypes = await pricingService.updateRuleTypes([
{
id: ruleTypeId,
name: "Region",
}
])
// do something with the rule types or return them
}
Parameters
sharedContext
Context