Stock Location Module
The Stock Location Module is the @medusajs/stock-location-next
NPM package that provides stock-location-related features in your Medusa and Node.js applications.
It's mainly useful with the Inventory Module.
This module is an updated version of the Stock Location Module part of the multi-warehouse feature. In Medusa V2, the previous version of the module will no longer be in use.
Features
Stock Location Management
Store and manage stock locations. Stock locations can be associated with other models that require a location, such as the Inventory Module's InventoryLevel.
Address Management
A stock location can have detailed address details.
Configure Stock Location Module
After installing the @medusajs/stock-location
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Stock Location Module's Service
You can use the Stock Location Module's main service by resolving from the dependency container the resource ModuleRegistrationName.STOCK_LOCATION
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const stockLocationModuleService: IStockLocationService =
request.scope.resolve(ModuleRegistrationName.STOCK_LOCATION)
res.json({
stock_locations: await stockLocationModuleService.list({}),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const stockLocationModuleService: IStockLocationService =
container.resolve(ModuleRegistrationName.STOCK_LOCATION)
const stockLocations = await stockLocationModuleService.list(
{}
)
}
import { createStep } from "@medusajs/workflows-sdk"
import { IStockLocationService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const stockLocationModuleService: IStockLocationService =
context.container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const stockLocations = await stockLocationModuleService.list(
{}
)
})