docs: edits and fixes to commerce module docs (#7468)

Apply edits and fixes to the commerce modules docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-29 11:08:06 +00:00
1 parent 130de74d6d
commit 2c5ba408d4
160 files changed
+6400 -3790

No files matched your search

@@ -8,4 +8,10 @@ export const metadata = {
Find in this reference the list of events emitted by the Product Module.
<Note type="soon">
Events are still in development, so this reference will change in the future.
</Note>
<EventsTable />
@@ -11,7 +11,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## Create Product
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -51,7 +51,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -96,7 +96,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## List Products
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -110,14 +110,14 @@ In this guide, you’ll find common examples of how you can use the Product Modu
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
const data = await productModuleService.list()
const products = await productModuleService.list()
res.json({ products: data })
res.json({ products })
}
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -129,19 +129,21 @@ In this guide, you’ll find common examples of how you can use the Product Modu
export async function GET(request: Request) {
const productModuleService = await initializeProductModule()
const data = await productModuleService.list()
const products = await productModuleService.list()
return NextResponse.json({ products: data })
return NextResponse.json({ products })
}
```
</CodeTab>
</CodeTabs>
---
## Retrieve a Product by its ID
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -155,16 +157,16 @@ In this guide, you’ll find common examples of how you can use the Product Modu
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
const data = await productModuleService.list({
id: request.params.id,
})
const product = await productModuleService.retrieve(
request.params.id
)
res.json({ product: data[0] })
res.json({ product })
}
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -180,11 +182,11 @@ In this guide, you’ll find common examples of how you can use the Product Modu
const { id } = params
const productModuleService = await initializeProductModule()
const data = await productModuleService.list({
id,
})
const product = await productModuleService.retrieve(
id
)
return NextResponse.json({ product: data[0] })
return NextResponse.json({ product })
}
```
@@ -196,7 +198,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## Retrieve a Product by its Handle
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -210,14 +212,16 @@ In this guide, you’ll find common examples of how you can use the Product Modu
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
const data = await productModuleService.list()
const data = await productModuleService.list({
handle: "shirt"
})
res.json({ products: data })
res.json({ product: data[0] })
}
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -229,59 +233,8 @@ In this guide, you’ll find common examples of how you can use the Product Modu
export async function GET(request: Request) {
const productModuleService = await initializeProductModule()
const data = await productModuleService.list()
return NextResponse.json({ products: data })
}
```
</CodeTab>
</CodeTabs>
## Retrieve a Product by its ID
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
request: MedusaRequest,
res: MedusaResponse
) {
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
const data = await productModuleService.list({
handle: request.params.handle,
})
res.json({ product: data[0] })
}
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
```ts
import { NextResponse } from "next/server"
import {
initialize as initializeProductModule,
} from "@medusajs/product"
export async function GET(
request: Request,
{ params }: { params: Record<string, any> }) {
const { handle } = params
const productModuleService = await initializeProductModule()
const data = await productModuleService.list({
handle,
handle: "shirt"
})
return NextResponse.json({ product: data[0] })
@@ -296,7 +249,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## Retrieve Categories
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -310,14 +263,14 @@ In this guide, you’ll find common examples of how you can use the Product Modu
const productModuleService: IProductModuleService =
request.scope.resolve(ModuleRegistrationName.PRODUCT)
const data = await productModuleService.listCategories()
const categories = await productModuleService.listCategories()
res.json({ categories: data })
res.json({ categories })
}
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -329,9 +282,9 @@ In this guide, you’ll find common examples of how you can use the Product Modu
export async function GET(request: Request) {
const productModuleService = await initializeProductModule()
const data = await productModuleService.listCategories()
const categories = await productModuleService.listCategories()
return NextResponse.json({ categories: data })
return NextResponse.json({ categories })
}
```
@@ -343,7 +296,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## Retrieve Category by Handle
<CodeTabs groupId="app-type">
<CodeTab label="medusa" value="Medusa API Router">
<CodeTab value="medusa" label="Medusa API Router">
```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
@@ -366,7 +319,7 @@ In this guide, you’ll find common examples of how you can use the Product Modu
```
</CodeTab>
<CodeTab label="nextjs" value="Next.js App Router">
<CodeTab value="nextjs" label="Next.js App Router">
```ts
import { NextResponse } from "next/server"
@@ -397,4 +350,4 @@ In this guide, you’ll find common examples of how you can use the Product Modu
## More Examples
The [Product Module interface reference](/references/product) provides a reference to all the methods available for use with examples for each.
The [Product Module's main service reference](/references/product) provides a reference to all the methods available for use with examples for each.
@@ -12,7 +12,7 @@ The Product Module is the `@medusajs/product` NPM package that provides product-
### Products Management
With the Product Module, store products and manage them through the main interface methods. Products have custom options, such as color or size, and each variant in the product sets the value for these options.
Store and manage products. Products have custom options, such as color or size, and each variant in the product sets the value for these options.
```ts
const products = await productService.create([
@@ -62,14 +62,16 @@ const products = await productService.update([
## Configure Product Module
After installing the `@medusajs/product` package in your Medusa application, add it to the `modules` object in `medusa-config.js`:
To use the Product Module, enable it in the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const { Modules } = require("@medusajs/modules-sdk")
// ...
const modules = {
// ...
productService: {
resolve: "@medusajs/product",
},
[Modules.PRODUCT]: true,
}
```
@@ -126,9 +128,11 @@ For example:
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const step1 = createStep(
"step-1",
async (_, { container }) => {
const productModuleService: IProductModuleService =
context.container.resolve(ModuleRegistrationName.PRODUCT)
container.resolve(ModuleRegistrationName.PRODUCT)
const products = await productModuleService.list()
})
@@ -4,21 +4,29 @@ export const metadata = {
# {metadata.title}
When Commerce Modules are used together in a Medusa application, the Medusa application handles building the relations between these modules.
This document showcases the link modules defined between the Product Module and other commerce modules.
This document showcases the relation between the Product Module and other Commerce Modules.
## Cart Module
{/* TODO add relation to:
A cart's line item is associated with a product and its variant. Medusa defines a link module that builds a relationship between the `Cart`, `Product`, and `ProductVariant` data models.
- shipping profile
![A diagram showcasing an example of how data models from the Cart and Product modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716546229/Medusa%20Resources/cart-product_x82x9j.jpg)
*/}
---
## Order Module
An order's line item is associated with the purchased product and its variant. Medusa defines a link module that builds a relationship between the `LineItem`, `Product`, and `ProductVariant` data models.
![A diagram showcasing an example of how data models from the Order and Product modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716556100/Medusa%20Resources/order-product_l6ylte.jpg)
---
## Pricing Module
A product variant’s prices are stored as money amounts belonging to a price set. The Medusa application forms a relation between the `ProductVariant` and the `PriceSet` data models.
A product variant’s prices are stored as money amounts belonging to a price set. Medusa defines a link module that builds a relationship between the `ProductVariant` and the `PriceSet` data models.
![A diagram showcasing an example of how resources from the Pricing and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651464/Medusa%20Resources/product-pricing_vlxsiq.jpg)
![A diagram showcasing an example of how data models from the Pricing and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651464/Medusa%20Resources/product-pricing_vlxsiq.jpg)
So, to add prices for a product variant, create a price set and add the prices as money amounts to it.
@@ -28,17 +36,17 @@ Learn more about the `PriceSet` data model in the [Pricing Concepts](../../prici
## Sales Channel Module
A product can have different availability in different sales channels. The Medusa application forms a relation between the `Product` and `SalesChannel` data models.
A product can have different availability in different sales channels. Medusa defines a link module that builds a relationship between the `Product` and `SalesChannel` data models.
![A diagram showcasing an example of how resources from the Product and Sales Channel modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651840/Medusa%20Resources/product-sales-channel_t848ik.jpg)
![A diagram showcasing an example of how data models from the Product and Sales Channel modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651840/Medusa%20Resources/product-sales-channel_t848ik.jpg)
---
## Inventory Module
Each product variant has different inventory details. The Medusa application forms a relation between the `ProductVariant` and `InventoryItem` data models.
Each product variant has different inventory details. Medusa defines a link module that builds a relationship between the `ProductVariant` and `InventoryItem` data models.
![A diagram showcasing an example of how resources from the Product and Inventory modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709652779/Medusa%20Resources/product-inventory_kmjnud.jpg)
![A diagram showcasing an example of how data models from the Product and Inventory modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709652779/Medusa%20Resources/product-inventory_kmjnud.jpg)
When the `manage_inventory` field of a product variant is enabled, you can manage the variant's inventory in different locations through this relation.