Stock Location Module

In this section of the documentation, you will find resources to learn more about the Stock Location Module and how to use it in your application.

Medusa has stock location related features available out-of-the-box through the Stock Location Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Stock Location Module.

NoteLearn more about why modules are isolated in this documentation.

Stock Location Features#


How to Use Stock Location Module's Service#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.

You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.

For example:

src/workflows/create-stock-location.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createStockLocationStep = createStep(10  "create-stock-location",11  async ({}, { container }) => {12    const stockLocationModuleService = container.resolve(Modules.STOCK_LOCATION)13
14    const stockLocation = await stockLocationModuleService.createStockLocations({15      name: "Warehouse 1",16    })17
18    return new StepResponse({ stockLocation }, stockLocation.id)19  },20  async (stockLocationId, { container }) => {21    if (!stockLocationId) {22      return23    }24    const stockLocationModuleService = container.resolve(Modules.STOCK_LOCATION)25
26    await stockLocationModuleService.deleteStockLocations([stockLocationId])27  }28)29
30export const createStockLocationWorkflow = createWorkflow(31  "create-stock-location",32  () => {33    const { stockLocation } = createStockLocationStep()34
35    return new WorkflowResponse({ stockLocation })36  }37)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Was this page helpful?
Edit this page