---
displayed_sidebar: pricingReference
badge:
  variant: orange
  text: Beta
slug: /references/pricing/addRules
sidebar_label: addRules
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# addRules - Pricing Module Reference

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

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

This method adds rules to a price set.

## Example

```ts
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

<ParameterTypes parameters={[
  {
    "name": "data",
    "type": "[AddRulesDTO](../../pricing/interfaces/pricing.AddRulesDTO.mdx)",
    "description": "The data defining the price set to add the rules to, along with the rules to add.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "priceSetId",
        "type": "`string`",
        "description": "The ID of the price set to add the rules to.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "rules",
        "type": "`object`[]",
        "description": "The rules to add to a price set.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "attribute",
            "type": "`string`",
            "description": "The value of the rule's `rule_attribute` attribute.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  },
  {
    "name": "sharedContext",
    "type": "[Context](../../pricing/interfaces/pricing.Context.mdx)",
    "description": "A context used to share resources, such as transaction manager, between the application and the module.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "enableNestedTransactions",
        "type": "`boolean`",
        "description": "A boolean value indicating whether nested transactions are enabled.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "isolationLevel",
        "type": "`string`",
        "description": "A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "manager",
        "type": "`TManager`",
        "description": "An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionId",
        "type": "`string`",
        "description": "A string indicating the ID of the current transaction.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionManager",
        "type": "`TManager`",
        "description": "An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

## Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[PriceSetDTO](../../pricing/interfaces/pricing.PriceSetDTO.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "The price set that the rules were added to.",
    "expandable": false,
    "children": [
      {
        "name": "id",
        "type": "`string`",
        "description": "The ID of the price set.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "money_amounts",
        "type": "[MoneyAmountDTO](../../pricing/interfaces/pricing.MoneyAmountDTO.mdx)[]",
        "description": "The prices that belong to this price set.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "amount",
            "type": "`number`",
            "description": "The price of this money amount.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "currency",
            "type": "[CurrencyDTO](../../pricing/interfaces/pricing.CurrencyDTO.mdx)",
            "description": "The money amount's currency.",
            "optional": true,
            "defaultValue": "",
            "expandable": true,
            "children": []
          },
          {
            "name": "currency_code",
            "type": "`string`",
            "description": "The currency code of this money amount.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "id",
            "type": "`string`",
            "description": "The ID of the money amount.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "max_quantity",
            "type": "`number`",
            "description": "The maximum quantity required to be purchased for this price to be applied.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "min_quantity",
            "type": "`number`",
            "description": "The minimum quantity required to be purchased for this price to be applied.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "price_set_money_amount",
            "type": "[PriceSetMoneyAmountDTO](../../pricing/interfaces/pricing.PriceSetMoneyAmountDTO.mdx)",
            "description": "The details of the relation between the money amount and its associated price set.",
            "optional": true,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      },
      {
        "name": "rule_types",
        "type": "[RuleTypeDTO](../../pricing/interfaces/pricing.RuleTypeDTO.mdx)[]",
        "description": "The rule types applied on this price set.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "default_priority",
            "type": "`number`",
            "description": "The priority of the rule type. This is useful when calculating the price of a price set, and multiple rules satisfy \nthe provided context. The higher the value, the higher the priority of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "id",
            "type": "`string`",
            "description": "The ID of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "name",
            "type": "`string`",
            "description": "The display name of the rule type.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          },
          {
            "name": "rule_attribute",
            "type": "`string`",
            "description": "The unique name used to later identify the rule\\_attribute. For example, it can be used in the `context` parameter of \nthe `calculatePrices` method to specify a rule for calculating the price.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />

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

This method adds rules to multiple price sets.

## Example

```ts
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

<ParameterTypes parameters={[
  {
    "name": "data",
    "type": "[AddRulesDTO](../../pricing/interfaces/pricing.AddRulesDTO.mdx)[]",
    "description": "The data defining the rules to add per price set.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "priceSetId",
        "type": "`string`",
        "description": "The ID of the price set to add the rules to.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "rules",
        "type": "`object`[]",
        "description": "The rules to add to a price set.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "attribute",
            "type": "`string`",
            "description": "The value of the rule's `rule_attribute` attribute.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  },
  {
    "name": "sharedContext",
    "type": "[Context](../../pricing/interfaces/pricing.Context.mdx)",
    "description": "A context used to share resources, such as transaction manager, between the application and the module.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "enableNestedTransactions",
        "type": "`boolean`",
        "description": "A boolean value indicating whether nested transactions are enabled.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "isolationLevel",
        "type": "`string`",
        "description": "A string indicating the isolation level of the context. Possible values are `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, or `SERIALIZABLE`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "manager",
        "type": "`TManager`",
        "description": "An instance of a manager, typically an entity manager, of type `TManager`, which is a typed parameter passed to the context to specify the type of the `manager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionId",
        "type": "`string`",
        "description": "A string indicating the ID of the current transaction.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "transactionManager",
        "type": "`TManager`",
        "description": "An instance of a transaction manager of type `TManager`, which is a typed parameter passed to the context to specify the type of the `transactionManager`.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

## Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[PriceSetDTO](../../pricing/interfaces/pricing.PriceSetDTO.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "The list of the price sets that the rules were added to.",
    "expandable": false,
    "children": [
      {
        "name": "PriceSetDTO[]",
        "type": "[PriceSetDTO](../../pricing/interfaces/pricing.PriceSetDTO.mdx)[]",
        "optional": false,
        "defaultValue": "",
        "description": "",
        "expandable": false,
        "children": [
          {
            "name": "PriceSetDTO",
            "type": "`object`",
            "description": "A price set's data.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />
