* docs improvements and changes * updated module definition * modules + dml changes * fix build * fix vale error * fix lint errors * fixes to stripe docs * fix condition * fix condition * fix module defintion * fix checkout * disable UI action * change oas preview action * flatten provider module options * fix lint errors * add module link docs * pr comments fixes * fix vale error * change node engine version * links -> linkable * add note about database name * small fixes * link fixes * fix response code in api reference * added migrations step
107 lines
2.7 KiB
Plaintext
107 lines
2.7 KiB
Plaintext
import { CodeTabs, CodeTab } from "docs-ui"
|
|
|
|
export const metadata = {
|
|
title: `Store Module`,
|
|
}
|
|
|
|
# {metadata.title}
|
|
|
|
The Store Module is the `@medusajs/store` NPM package that provides store-related features in your Medusa and Node.js applications.
|
|
|
|
## Features
|
|
|
|
### Store Management
|
|
|
|
A store holds the main configurations of your commerce store, such as supported currencies, default region and sales channel, and more.
|
|
|
|
```ts
|
|
const store = await storeModuleService.createStores({
|
|
name: "My Store",
|
|
supported_currency_codes: ["usd"],
|
|
})
|
|
```
|
|
|
|
### Multi-Tenancy Support
|
|
|
|
You can create multiple stores, each having its own configurations.
|
|
|
|
```ts
|
|
const stores = await storeModuleService.createStores([
|
|
{
|
|
name: "USA Store",
|
|
supported_currency_codes: ["usd"],
|
|
},
|
|
{
|
|
name: "Europe Store",
|
|
supported_currency_codes: ["eur"],
|
|
},
|
|
])
|
|
```
|
|
|
|
---
|
|
|
|
## How to Use Store Module's Service
|
|
|
|
You can use the Store Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.STORE` imported from `@medusajs/modules-sdk`.
|
|
|
|
For example:
|
|
|
|
<CodeTabs groupId="resource-type">
|
|
<CodeTab label="API Route" value="api-route">
|
|
|
|
```ts title="src/api/store/custom/route.ts"
|
|
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
|
import { IStoreModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
export async function GET(
|
|
request: MedusaRequest,
|
|
res: MedusaResponse
|
|
): Promise<void> {
|
|
const storeModuleService: IStoreModuleService = request.scope.resolve(
|
|
ModuleRegistrationName.STORE
|
|
)
|
|
|
|
res.json({
|
|
stores: await storeModuleService.listStores(),
|
|
})
|
|
}
|
|
```
|
|
|
|
</CodeTab>
|
|
<CodeTab label="Subscriber" value="subscribers">
|
|
|
|
```ts title="src/subscribers/custom-handler.ts"
|
|
import { SubscriberArgs } from "@medusajs/medusa"
|
|
import { IStoreModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
|
const storeModuleService: IStoreModuleService = container.resolve(
|
|
ModuleRegistrationName.STORE
|
|
)
|
|
|
|
const stores = await storeModuleService.listStores()
|
|
}
|
|
```
|
|
|
|
</CodeTab>
|
|
<CodeTab label="Workflow Step" value="workflow-step">
|
|
|
|
```ts title="src/workflows/hello-world/step1.ts"
|
|
import { createStep } from "@medusajs/workflows-sdk"
|
|
import { IStoreModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/utils"
|
|
|
|
const step1 = createStep("step-1", async (_, { container }) => {
|
|
const storeModuleService: IStoreModuleService = container.resolve(
|
|
ModuleRegistrationName.STORE
|
|
)
|
|
|
|
const stores = await storeModuleService.listStores()
|
|
})
|
|
```
|
|
|
|
</CodeTab>
|
|
</CodeTabs>
|