Skip to main content
Skip to main content

listPriceListRules - Pricing Module Reference

Beta

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

This method is used to retrieve a paginated list of price list rules based on optional filters and configuration.

Example

To retrieve a list of price list vs using their IDs:

import {
initialize as initializePricingModule,
} from "@medusajs/pricing"

async function listPriceListRules (priceListRuleIds: string[]) {
const pricingService = await initializePricingModule()

const priceListRules = await pricingService.listPriceListRules(
{
id: priceListRuleIds
},
)

// do something with the price list rules or return them
}

To specify relations that should be retrieved within the price list rules:

import {
initialize as initializePricingModule,
} from "@medusajs/pricing"

async function listPriceListRules (priceListRuleIds: string[]) {
const pricingService = await initializePricingModule()

const priceListRules = await pricingService.listPriceListRules(
{
id: priceListRuleIds
},
{
relations: ["price_list_rule_values"]
}
)

// do something with the price list 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 listPriceListRules (priceListRuleIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()

const priceListRules = await pricingService.listPriceListRules(
{
id: priceListRuleIds
},
{
relations: ["price_list_rule_values"],
skip,
take
}
)

// do something with the price list 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 listPriceListRules (priceListRuleIds: string[], ruleTypeIDs: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()

const priceListRules = await pricingService.listPriceListRules(
{
$and: [
{
id: priceListRuleIds
},
{
rule_types: ruleTypeIDs
}
]
},
{
relations: ["price_list_rule_values"],
skip,
take
}
)

// do something with the price list rules or return them
}

Parameters

The filters to apply on the retrieved price list rules.
The configurations determining how the price list rules are retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a price list rule.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<PriceListRuleDTO[]>Required
The list of price list rules.
Was this section helpful?