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:
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
Step 3: Run Migrations
Run the following commands to reflect schema changes into your database:
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()
})
}
import {
type SubscriberConfig,
type SubscriberArgs,
PricingService,
} from "@medusajs/medusa"
import {
PricingModuleService
} from "@medusajs/pricing"
export default async function handleListPriceSets({
data, eventName, container, pluginOptions
}: SubscriberArgs<Customer>) {
const pricingModuleService: PricingModuleService =
container.resolve(
"pricingModuleService"
)
console.log(await pricingModuleService.list())
}
export const config: SubscriberConfig = {
event: PricingService.Events.CREATED,
context: {
subscriberId: "list-pricings"
}
}
import { TransactionBaseService } from "@medusajs/medusa"
import {
PricingModuleService
} from "@medusajs/pricing"
class HelloService extends TransactionBaseService {
private pricingModuleService: PricingModuleService
constructor(container) {
super(container)
this.pricingModuleService = container.pricingModuleService
}
await listPriceSets() {
return await this.pricingModuleService.list()
}
}
export default HelloService
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?