Store Module

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

Medusa has store related features available out-of-the-box through the Store 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 Store Module.

NoteLearn more about why modules are isolated in this documentation.

Store Features#


How to Use Store 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-store.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createStoreStep = createStep(10  "create-store",11  async ({}, { container }) => {12    const storeModuleService = container.resolve(Modules.STORE)13
14    const store = await storeModuleService.createStores({15      name: "My Store",16      supported_currencies: [{17        currency_code: "usd",18        is_default: true,19      }],20    })21
22    return new StepResponse({ store }, store.id)23  },24  async (storeId, { container }) => {25    if(!storeId) {26      return27    }28    const storeModuleService = container.resolve(Modules.STORE)29    30    await storeModuleService.deleteStores([storeId])31  }32)33
34export const createStoreWorkflow = createWorkflow(35  "create-store",36  () => {37    const { store } = createStoreStep()38
39    return new WorkflowResponse({ store })40  }41)

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