Pricing Module
The Pricing Module is the @medusajs/pricing
NPM package that provides pricing-related features in your Medusa and Node.js applications.
Features
Price Management
With the Pricing Module, store the prices of a resource and manage them through the main interface'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.
Advanced Rule Engine
Create custom rules and apply them to prices. This gives you more flexibility in how you condition prices, filter them, and ensure the best prices are retrieved for custom contexts.
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.
Price Calculation Strategy
The module’s main service provides a calculatePrices
method to retrieve the best price for a given context.
You can use your custom rules here to find the best price for the specified rule values.
Configure Pricing Module
After installing the @medusajs/pricing
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Pricing Module's Service
You can use the Pricing Module's main service by resolving from the dependency container the resource ModuleRegistrationName.PRICING
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IPricingModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const pricingModuleService: IPricingModuleService =
request.scope.resolve(ModuleRegistrationName.PRICING)
res.json({
price_sets: await pricingModuleService.list(),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { IPricingModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const pricingModuleService: IPricingModuleService =
container.resolve(ModuleRegistrationName.PRICING)
const priceSets = await pricingModuleService.list()
}
import { createStep } from "@medusajs/workflows-sdk"
import { IPricingModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const pricingModuleService: IPricingModuleService =
context.container.resolve(ModuleRegistrationName.PRICING)
const priceSets = await pricingModuleService.list()
})