Skip to main content
Skip to main content

Install Pricing Module in Medusa

In this document, you'll learn how to install the Pricing Module using NPM in the Medusa backend.

Step 1: Install Module

To install the Pricing Module, run the following command in the root directory of the Medusa backend:

npm install @medusajs/pricing

Step 2: Add Module to Configurations

In medusa-config.js, add the Pricing Module to the exported object under the modules property:

medusa-config.js
module.exports = {
// ...
featureFlags: {
// ...
medusa_v2: true,
},
modules: {
// ...
pricingService: {
resolve: "@medusajs/pricing",
},
},
}

Step 3: Run Migrations

Run the following commands to reflect schema changes into your database:

npx medusa migrations run
node node_modules/@medusajs/medusa/dist/scripts/migrate-to-pricing-module.js

Use the Module

You can now start using the module's PricingModuleService by resolving it through dependency injection.

For example:

import type { 
MedusaRequest,
MedusaResponse
} from "@medusajs/medusa";
import {
PricingModuleService
} from "@medusajs/pricing"

export async function GET(
req: MedusaRequest,
res: MedusaResponse
) {
const pricingModuleService: PricingModuleService =
req.scope.resolve(
"pricingModuleService"
)

return res.json({
pricings: pricingModuleService.list()
})
}

Start Development

You can refer to the Example Usages documentation page for examples of using the Pricing Module.

You can also refer to the Module Interface Reference for a detailed reference on all available methods.

Was this section helpful?