Skip to main content
Skip to main content

addRules - Pricing Module Reference

Beta

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

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

dataAddRulesDTORequired
The data defining the price set to add the rules to, along with the rules 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 rules were added to.

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

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

dataAddRulesDTO[]Required
The data defining the rules 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 the rules were added to.
Was this section helpful?