addRules - Pricing Module Reference
BetaThis documentation provides a reference to the addRules method. This belongs to the Pricing Module.
addRules(data, sharedContext?): Promise<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
The data defining the price set to add the rules to, along with the rules to add.
sharedContextContextA context used to share resources, such as transaction manager, between the application and the module.
sharedContextContextReturns
The price set that the rules were added to.
addRules(data, sharedContext?): Promise<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
The data defining the rules 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 the rules were added to.
Was this section helpful?