Inventory Module
The Inventory Module is the @medusajs/inventory-next
NPM package that provides inventory-related features in your Medusa and Node.js applications.
This module is an updated version of the Inventory Module part of the multi-warehouse feature. In Medusa V2, the previous version of the module will no longer be in use.
Features
Inventory Items Management
Store and manage inventory of any stock-kept item, such as product variants.
Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping.
Inventory Across Locations
Inventory items' quantities are set per locations through inventory levels. This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses.
Reservation Management
Reserve quantities of inventory items at specific locations for orders or other purposes. The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation.
Check Inventory Availability
Check whether an inventory item has the necessary quantity for purchase. Any reserved quantity is considered unavailable, even if the inventory item's quantity hasn't been adjusted yet.
Configure Inventory Module
After installing the @medusajs/inventory-next
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Inventory Module's Service
You can use the Inventory Module's main service by resolving from the dependency container the resource ModuleRegistrationName.INVENTORY
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const inventoryModuleService: IInventoryService =
request.scope.resolve(ModuleRegistrationName.INVENTORY)
res.json({
inventory_items:
await inventoryModuleService.list({}),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const inventoryModuleService: IInventoryService =
container.resolve(ModuleRegistrationName.INVENTORY)
const inventoryItems =
await inventoryModuleService.list({})
}
import { createStep } from "@medusajs/workflows-sdk"
import { IInventoryService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const inventoryModuleService: IInventoryService =
context.container.resolve(ModuleRegistrationName.INVENTORY)
const inventoryItems =
await inventoryModuleService.list({})
})