docs: improved commerce modules [5/5] (#9592)
- Improve remaining commerce modules - Other: add a note about using methods of the modules' main services.
This commit is contained in:
1 parent
6e856d3156
commit
eed88c95ec
42 files changed
+594
-582
No files matched your search
@@ -4,13 +4,13 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this document, you’ll learn about the main concepts in the Stock Location Module, and how data is stored and related.
|
||||
In this document, you’ll learn about the main concepts in the Stock Location Module.
|
||||
|
||||
## Stock Location
|
||||
|
||||
A stock location, represented by the `StockLocation` data model, represents a location where stock items are kept. For example, a warehouse.
|
||||
|
||||
The `InventoryLevel` and `ReservationItem` data models of the Inventory Module are associated with the `StockLocation` to provide inventory details per location. Learn more about this relation in [this guide](../relations-to-other-modules/page.mdx).
|
||||
Medusa uses stock locations to provide inventory details, from the Inventory Module, per location.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -8,21 +8,26 @@ export const metadata = {
|
||||
|
||||
In this document, you’ll find common examples of how you can use the Stock Location Module in your application.
|
||||
|
||||
<Note>
|
||||
|
||||
You should only use the Stock Location Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
## Create a Stock Location
|
||||
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const stockLocationModuleService: IStockLocationService =
|
||||
const stockLocationModuleService =
|
||||
request.scope.resolve(Modules.STOCK_LOCATION)
|
||||
|
||||
const stockLocation = await stockLocationModuleService.createStockLocations({
|
||||
@@ -64,16 +69,15 @@ export async function POST(request: Request) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const stockLocationModuleService: IStockLocationService =
|
||||
const stockLocationModuleService =
|
||||
request.scope.resolve(Modules.STOCK_LOCATION)
|
||||
|
||||
res.json({
|
||||
@@ -109,16 +113,15 @@ export async function GET(request: Request) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function POST(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const stockLocationModuleService: IStockLocationService =
|
||||
const stockLocationModuleService =
|
||||
request.scope.resolve(Modules.STOCK_LOCATION)
|
||||
|
||||
const stockLocation = await stockLocationModuleService.updateStockLocations({
|
||||
@@ -174,16 +177,15 @@ export async function POST(request: Request) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function DELETE(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const stockLocationModuleService: IStockLocationService =
|
||||
const stockLocationModuleService =
|
||||
request.scope.resolve(Modules.STOCK_LOCATION)
|
||||
|
||||
await stockLocationModuleService.deleteStockLocations("sloc_123")
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
export const metadata = {
|
||||
title: `Links between Stock Location Module and Other Modules`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This document showcases the module links defined between the Stock Location Module and other commerce modules.
|
||||
|
||||
## Fulfillment Module
|
||||
|
||||
A fulfillment set can be conditioned to a specific stock location.
|
||||
|
||||
Medusa defines a link between the `FulfillmentSet` and `StockLocation` data models.
|
||||
|
||||

|
||||
|
||||
Medusa also defines a link between the `FulfillmentProvider` and `StockLocation` data models to indicate the providers that can be used in a location.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Sales Channel Module
|
||||
|
||||
A stock location is associated with a sales channel. This scopes inventory quantities in a stock location by the associated sales channel.
|
||||
|
||||
Medusa defines a link between the `SalesChannel` and `StockLocation` data models.
|
||||
|
||||

|
||||
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
The Stock Location Module is the `@medusajs/medusa/stock-location-next` NPM package that provides stock-location-related features in your Medusa and Node.js applications.
|
||||
The Stock Location Module provides stock-location-related features in your Medusa and Node.js applications.
|
||||
|
||||
## How to Use Stock Location Module's Service
|
||||
|
||||
@@ -15,18 +15,33 @@ You can use the Stock Location Module's main service by resolving from the Medus
|
||||
For example:
|
||||
|
||||
<CodeTabs groupId="resource-type">
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const stockLocationModuleService = container.resolve(
|
||||
Modules.STOCK_LOCATION
|
||||
)
|
||||
|
||||
const stockLocations = await stockLocationModuleService.listStockLocations({})
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="API Route" value="api-route">
|
||||
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
request: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const stockLocationModuleService: IStockLocationService =
|
||||
const stockLocationModuleService =
|
||||
request.scope.resolve(Modules.STOCK_LOCATION)
|
||||
|
||||
res.json({
|
||||
@@ -38,35 +53,17 @@ export async function GET(
|
||||
</CodeTab>
|
||||
<CodeTab label="Subscriber" value="subscribers">
|
||||
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
||||
const stockLocationModuleService: IStockLocationService = container.resolve(
|
||||
const stockLocationModuleService = container.resolve(
|
||||
Modules.STOCK_LOCATION
|
||||
)
|
||||
|
||||
const stockLocations = await stockLocationModuleService.listStockLocations({})
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { IStockLocationService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const stockLocationModuleService: IStockLocationService = container.resolve(
|
||||
Modules.STOCK_LOCATION
|
||||
)
|
||||
|
||||
const stockLocations = await stockLocationModuleService.listStockLocations({})
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
export const metadata = {
|
||||
title: `Relations between Stock Location Module and Other Modules`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This document showcases the link modules defined between the Stock Location Module and other commerce modules.
|
||||
|
||||
## Fulfillment Module
|
||||
|
||||
A fulfillment set can be conditioned to a specific stock location. Medusa defines a link module that builds a relationship between the `FulfillmentSet` and `StockLocation` data models.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## Inventory Module
|
||||
|
||||
Reservation items and inventory items are associated with a location. Medusa defines a link module that builds a relationship between the `ReservationItem` and `StockLocation` data models, and the `InventoryLevel` and `StockLocation` data models.
|
||||
|
||||

|
||||
|
||||
With this relation, stock and reserved quantity is specific to a location, providing you with more flexibility. The location can be as simple as having only a name, and more flexible by adding more address details to it.
|
||||
|
||||
---
|
||||
|
||||
## Sales Channel Module
|
||||
|
||||
A stock location is associated with a sales channel. This scopes inventory quantities associated with that stock location by the associated sales channel.
|
||||
|
||||
Medusa defines a link module that builds a relationship between the `SalesChannel` and `StockLocation` data models.
|
||||
|
||||

|
||||
Reference in new issue
Block a user