Product Module
The Product Module is the @medusajs/product
NPM package that provides product-related features in your Medusa and Node.js applications.
Features
Products Management
With the Product Module, store products and manage them through the main interface methods. Products have custom options, such as color or size, and each variant in the product sets the value for these options.
Product Organization
The Product Module provides different data models used to organize products, including categories, collections, tags, and more.
Configure Product Module
After installing the @medusajs/product
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Product Module's Service
You can use the Product Module's main service by resolving from the dependency container the resource ModuleRegistrationName.PRODUCT
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
) {
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
res.json({ products: await productModuleService.list() })
}
import { SubscriberArgs } from "@medusajs/medusa"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const productModuleService: IProductModuleService =
container.resolve(ModuleRegistrationName.PRODUCT)
const products = await productModuleService.list()
}
import { createStep } from "@medusajs/workflows-sdk"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const productModuleService: IProductModuleService =
context.container.resolve(ModuleRegistrationName.PRODUCT)
const products = await productModuleService.list()
})