Commerce Modules

Pricing Module

The Pricing Module is the @medusajs/medusa/pricing NPM package that provides pricing-related features in your Medusa and Node.js applications.

How to Use Pricing Module's Service#

You can use the Pricing Module's main service by resolving from the Medusa container the resource Modules.PRICING imported from @medusajs/framework/utils.

For example:


Features#

Price Management#

With the Pricing Module, store the prices of a resource and manage them through the main service's methods.

Prices are grouped in a price set, allowing you to add more than one price for a resource based on different conditions, such as currency code.

Code
1const priceSet = await pricingModuleService.createPriceSets({2  prices: [3    {4      amount: 500,5      currency_code: "USD",6    },7    {8      amount: 400,9      currency_code: "EUR",10      min_quantity: 0,11      max_quantity: 4,12      rules: {},13    },14  ],15})

Advanced Rule Engine#

Create prices with custom rules. This gives you more flexibility in how you condition prices, filter them, and ensure the best prices are retrieved for custom contexts.

Code
1const priceSet = await pricingModuleService.addPrices({2  priceSetId: "pset_123",3  prices: [4    {5      amount: 500,6      currency_code: "EUR",7      rules: {8        region_id: "reg_123",9      },10    },11  ],12})

Price Lists#

Price lists allow you to group prices and apply them only in specific conditions. You can also use them to override existing prices for the specified conditions.

Code
1const priceList = await pricingModuleService.createPriceLists([2  {3    title: "My Sale",4    description: "Sale on selected items.",5    type: "sale",6    starts_at: Date.parse("01/10/2023").toString(),7    ends_at: Date.parse("31/10/2023").toString(),8    rules: {9      region_id: ["reg_123", "reg_321"],10    },11    prices: [12      {13        amount: 400,14        currency_code: "EUR",15        price_set_id: "pset_123",16      },17    ],18  },19])

Price Calculation Strategy#

Retrieve the best price in a given context and for the specified rule values.

Code
1const price = await pricingModuleService.calculatePrices(2  { id: ["pset_123"] },3  {4    context: {5      currency_code: "EUR",6      region_id: "reg_123",7    },8  }9)
Was this page helpful?
Edit this page