Skip to main content
Skip to main content

listAndCountPriceListRules - Pricing Module Reference

Beta

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

This method is used to retrieve a paginated list of price list ruless along with the total count of available price list ruless satisfying the provided filters.

Example

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

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

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

const [priceListRules, count] = await pricingService.listAndCountPriceListRules(
{
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 listAndCountPriceListRules (priceListRuleIds: string[]) {
const pricingService = await initializePricingModule()

const [priceListRules, count] = await pricingService.listAndCountPriceListRules(
{
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 listAndCountPriceListRules (priceListRuleIds: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()

const [priceListRules, count] = await pricingService.listAndCountPriceListRules(
{
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 listAndCountPriceListRules (priceListRuleIds: string[], ruleTypeIDs: string[], skip: number, take: number) {
const pricingService = await initializePricingModule()

const [priceListRules, count] = await pricingService.listAndCountPriceListRules(
{
$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[], number]>Required
The list of price list rules along with their total count.
Was this section helpful?