diff --git a/www/apps/book/app/learn/introduction/build-with-llms-ai/page.mdx b/www/apps/book/app/learn/introduction/build-with-llms-ai/page.mdx
new file mode 100644
index 0000000000..40e687a983
--- /dev/null
+++ b/www/apps/book/app/learn/introduction/build-with-llms-ai/page.mdx
@@ -0,0 +1,66 @@
+import { InlineIcon } from "docs-ui"
+import { AiAssistent, AiAssistentLuminosity } from "@medusajs/icons"
+
+export const metadata = {
+ title: `${pageNumber} Build with AI Assistants and LLMs`,
+}
+
+# {metadata.title}
+
+In this chapter, you'll learn how you can use AI assistants and LLMs effectively in your Medusa development.
+
+## AI Assistant in Documentation
+
+The Medusa documentation is equipped with an AI Assistant that can answer your questions and help you build customizations with Medusa.
+
+### Open the AI Assistant
+
+To open the AI Assistant, either:
+
+- Use the keyboard shortcut `Ctrl + I` for Windows/Linux, or `Cmd + I` for macOS.
+- Click the icon in the top right corner of the documentation.
+
+You can then ask the AI Assistant any questions about Medusa, such as:
+
+- What is a workflow?
+- How to create a product review module?
+- How to update Medusa?
+- How to fix this error?
+
+The AI Assistant will provide you with relevant documentation links, code snippets, and explanations to help you with your development.
+
+### Ask About Code Snippets
+
+While browsing the documentation, you'll find a icon in the header of code snippets. You can click this icon to ask the AI Assistant about the code snippet.
+
+The AI Assistant will analyze the code and provide explanations, usage examples, and any additional information you need to understand how the code works.
+
+### Ask About Documentation Pages
+
+If you need more help understanding a specific documentation page, you can click the "Explain with AI Assistant" link in the page's right sidebar. This will open the AI Assistant and provide context about the current page, allowing you to ask questions related to the content.
+
+### Formatting and Code Blocks
+
+In your questions to the AI Assistant, you can format code blocks by wrapping them in triple backticks (```). For example:
+
+~~~markdown
+```
+console.log("Hello, World!")
+```
+~~~
+
+You can add new lines using the `Shift + Enter` shortcut.
+
+---
+
+## Plain Text Documentation
+
+The Medusa documentation is available in plain text format, which allows LLMs and AI tools to easily parse and understand the content.
+
+You can access the following plain text documentation files:
+
+- [llms.txt](https://docs.medusajs.com/llms.txt) - Contains a short structure of links to important documentation pages.
+- [llms-full.txt](https://docs.medusajs.com/llms-full.txt) - Contains the full documentation content, including all pages and sections.
+- **Markdown version of any page** - You can access the Markdown version of any documentation page by appending `/index.html.md` to the page URL. For example, the plain text content of the current page is available at [https://docs.medusajs.com/learn/introduction/build-with-llms-ai/index.html.md](https://docs.medusajs.com/learn/introduction/build-with-llms-ai/index.html.md).
+
+You can provide these files to your AI tools or LLM editors like [Cursor](https://docs.cursor.com/context/@-symbols/@-docs). This will help them understand the Medusa documentation and provide better assistance when building customizations or answering questions.
diff --git a/www/apps/book/app/learn/page.mdx b/www/apps/book/app/learn/page.mdx
index 703576f824..b6cece0e80 100644
--- a/www/apps/book/app/learn/page.mdx
+++ b/www/apps/book/app/learn/page.mdx
@@ -156,10 +156,6 @@ This documentation is split into the following sections:
To get started, check out the [Installation chapter](./installation/page.mdx).
-### Using with LLM Editors
-
-This documentation provides an [llms-full.txt](https://docs.medusajs.com/llms-full.txt) file to support LLM editors. To access the documentation directly from your editor and benefit from code generation, add [https://docs.medusajs.com/llms-full.txt](https://docs.medusajs.com/llms-full.txt) as a custom documentation source in your LLM editor, such as [Cursor](https://docs.cursor.com/context/@-symbols/@-docs).
-
---
## Useful Links
diff --git a/www/apps/book/generated/edit-dates.mjs b/www/apps/book/generated/edit-dates.mjs
index e398125e8a..e522a42138 100644
--- a/www/apps/book/generated/edit-dates.mjs
+++ b/www/apps/book/generated/edit-dates.mjs
@@ -2,7 +2,7 @@ export const generatedEditDates = {
"app/learn/fundamentals/scheduled-jobs/page.mdx": "2024-12-09T10:51:40.570Z",
"app/learn/fundamentals/workflows/page.mdx": "2024-12-09T14:45:17.837Z",
"app/learn/deployment/page.mdx": "2025-06-20T08:36:29.097Z",
- "app/learn/page.mdx": "2025-05-01T15:30:08.238Z",
+ "app/learn/page.mdx": "2025-06-27T11:39:15.941Z",
"app/learn/fundamentals/modules/commerce-modules/page.mdx": "2025-04-17T08:51:32.723Z",
"app/learn/fundamentals/workflows/retry-failed-steps/page.mdx": "2025-03-28T07:15:19.388Z",
"app/learn/fundamentals/workflows/workflow-hooks/page.mdx": "2024-12-09T10:44:33.781Z",
@@ -122,5 +122,6 @@ export const generatedEditDates = {
"app/learn/fundamentals/workflows/errors/page.mdx": "2025-04-25T14:26:25.000Z",
"app/learn/fundamentals/api-routes/override/page.mdx": "2025-05-09T08:01:24.493Z",
"app/learn/fundamentals/module-links/index/page.mdx": "2025-05-23T07:57:58.958Z",
- "app/learn/fundamentals/module-links/index-module/page.mdx": "2025-06-19T16:02:05.665Z"
+ "app/learn/fundamentals/module-links/index-module/page.mdx": "2025-06-19T16:02:05.665Z",
+ "app/learn/introduction/build-with-llms-ai/page.mdx": "2025-06-27T12:07:08.147Z"
}
\ No newline at end of file
diff --git a/www/apps/book/generated/sidebar.mjs b/www/apps/book/generated/sidebar.mjs
index a776f67aa3..753fc9c7ee 100644
--- a/www/apps/book/generated/sidebar.mjs
+++ b/www/apps/book/generated/sidebar.mjs
@@ -38,6 +38,16 @@ export const generatedSidebars = [
"children": [],
"chapterTitle": "1.3. Architecture",
"number": "1.3."
+ },
+ {
+ "loaded": true,
+ "isPathHref": true,
+ "type": "link",
+ "title": "AI Assistants and LLMs",
+ "path": "/learn/introduction/build-with-llms-ai",
+ "children": [],
+ "chapterTitle": "1.4. AI Assistants and LLMs",
+ "number": "1.4."
}
],
"chapterTitle": "1. Getting Started",
diff --git a/www/apps/book/public/llms-full.txt b/www/apps/book/public/llms-full.txt
index b5acae8ef7..67fb9d64c6 100644
--- a/www/apps/book/public/llms-full.txt
+++ b/www/apps/book/public/llms-full.txt
@@ -18737,6 +18737,67 @@ The following diagram illustrates Medusa's architecture including all its layers

+# Build with AI Assistants and LLMs
+
+In this chapter, you'll learn how you can use AI assistants and LLMs effectively in your Medusa development.
+
+## AI Assistant in Documentation
+
+The Medusa documentation is equipped with an AI Assistant that can answer your questions and help you build customizations with Medusa.
+
+### Open the AI Assistant
+
+To open the AI Assistant, either:
+
+- Use the keyboard shortcut `Ctrl + I` for Windows/Linux, or `Cmd + I` for macOS.
+- Click the icon in the top right corner of the documentation.
+
+You can then ask the AI Assistant any questions about Medusa, such as:
+
+- What is a workflow?
+- How to create a product review module?
+- How to update Medusa?
+- How to fix this error?
+
+The AI Assistant will provide you with relevant documentation links, code snippets, and explanations to help you with your development.
+
+### Ask About Code Snippets
+
+While browsing the documentation, you'll find a icon in the header of code snippets. You can click this icon to ask the AI Assistant about the code snippet.
+
+The AI Assistant will analyze the code and provide explanations, usage examples, and any additional information you need to understand how the code works.
+
+### Ask About Documentation Pages
+
+If you need more help understanding a specific documentation page, you can click the "Explain with AI Assistant" link in the page's right sidebar. This will open the AI Assistant and provide context about the current page, allowing you to ask questions related to the content.
+
+### Formatting and Code Blocks
+
+In your questions to the AI Assistant, you can format code blocks by wrapping them in triple backticks (\`\`\`). For example:
+
+````markdown
+```
+console.log("Hello, World!")
+```
+````
+
+You can add new lines using the `Shift + Enter` shortcut.
+
+***
+
+## Plain Text Documentation
+
+The Medusa documentation is available in plain text format, which allows LLMs and AI tools to easily parse and understand the content.
+
+You can access the following plain text documentation files:
+
+- [llms.txt](https://docs.medusajs.com/llms.txt/index.html.md) - Contains a short structure of links to important documentation pages.
+- [llms-full.txt](https://docs.medusajs.com/llms-full.txt/index.html.md) - Contains the full documentation content, including all pages and sections.
+- **Markdown version of any page** - You can access the Markdown version of any documentation page by appending `/index.html.md` to the page URL. For example, the plain text content of the current page is available at [https://docs.medusajs.com/learn/introduction/build-with-llms-ai/index.html.md](https://docs.medusajs.com/learn/introduction/build-with-llms-ai/index.html.md).
+
+You can provide these files to your AI tools or LLM editors like [Cursor](https://docs.cursor.com/context/@-symbols/@-docs). This will help them understand the Medusa documentation and provide better assistance when building customizations or answering questions.
+
+
# Introduction
Medusa is a digital commerce platform with a built-in Framework for customization.
@@ -18791,10 +18852,6 @@ This documentation is split into the following sections:
To get started, check out the [Installation chapter](https://docs.medusajs.com/learn/installation/index.html.md).
-### Using with LLM Editors
-
-This documentation provides an [llms-full.txt](https://docs.medusajs.com/llms-full.txt/index.html.md) file to support LLM editors. To access the documentation directly from your editor and benefit from code generation, add [https://docs.medusajs.com/llms-full.txt](https://docs.medusajs.com/llms-full.txt/index.html.md) as a custom documentation source in your LLM editor, such as [Cursor](https://docs.cursor.com/context/@-symbols/@-docs).
-
***
## Useful Links
@@ -47121,7 +47178,7 @@ To learn more about the commerce features that Medusa provides, check out Medusa
In this tutorial, you'll learn how to implement first-purchase discounts in Medusa.
-When you install a Medusa application, you get a fully-fledged commerce platform with a Framework for customization. The Medusa application's commerce features are built around [Commerce Modules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/index.html.md), which are available out-of-the-box. These features include promotion and discount management features.
+When you install a Medusa application, you get a fully-fledged commerce platform with a Framework for customization. The Medusa application's commerce features are built around [Commerce Modules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/index.html.md), which are available out-of-the-box. These features include promotion and cart management features.
The first-purchase discount feature encourages customers to sign up and make their first purchase by offering them a discount. In this tutorial, you'll learn how to implement this feature in Medusa.
@@ -47248,8 +47305,8 @@ export const applyFirstPurchasePromoWorkflow = createWorkflow(
entity: "cart",
fields: ["promotions.*", "customer.*", "customer.orders.*"],
filters: {
- id: input.cart_id
- }
+ id: input.cart_id,
+ },
})
const { data: promotions } = useQueryGraphStep({
@@ -47262,7 +47319,7 @@ export const applyFirstPurchasePromoWorkflow = createWorkflow(
when({
carts,
- promotions
+ promotions,
}, (data) => {
return data.promotions.length > 0 &&
!data.carts[0].promotions?.some((promo) => promo?.id === data.promotions[0].id) &&
@@ -47273,7 +47330,7 @@ export const applyFirstPurchasePromoWorkflow = createWorkflow(
updateCartPromotionsStep({
id: carts[0].id,
promo_codes: [promotions[0].code!],
- action: PromotionActions.ADD
+ action: PromotionActions.ADD,
})
})
@@ -47282,8 +47339,8 @@ export const applyFirstPurchasePromoWorkflow = createWorkflow(
entity: "cart",
fields: ["*", "promotions.*"],
filters: {
- id: input.cart_id
- }
+ id: input.cart_id,
+ },
}).config({ name: "retrieve-updated-cart" })
return new WorkflowResponse(updatedCarts[0])
@@ -47332,8 +47389,8 @@ export default async function cartCreatedHandler({
await applyFirstPurchasePromoWorkflow(container)
.run({
input: {
- cart_id: data.id
- }
+ cart_id: data.id,
+ },
})
}
@@ -47431,8 +47488,8 @@ updateCartPromotionsWorkflow.hooks.validate(
entity: "customer",
fields: ["orders.*", "has_account"],
filters: {
- id: cart.customer_id
- }
+ id: cart.customer_id,
+ },
})
if (!customer.has_account || (customer?.orders?.length || 0) > 0) {
@@ -47472,7 +47529,7 @@ In the same `src/workflows/hooks/validate-promotion.ts` file, add the following
```ts title="src/workflows/hooks/validate-promotion.ts"
import {
- completeCartWorkflow
+ completeCartWorkflow,
} from "@medusajs/medusa/core-flows"
```
@@ -47502,8 +47559,8 @@ completeCartWorkflow.hooks.validate(
entity: "customer",
fields: ["orders.*", "has_account"],
filters: {
- id: cart.customer_id
- }
+ id: cart.customer_id,
+ },
})
if (!customer.has_account || (customer?.orders?.length || 0) > 0) {
@@ -47711,6 +47768,635 @@ If you encounter issues not covered in the troubleshooting guides:
2. Join the [Medusa Discord community](https://discord.gg/medusajs) for real-time support from community members.
+# Add Gift Message to Line Items in Medusa
+
+In this tutorial, you will learn how to add a gift message to items in carts and orders in Medusa.
+
+When you install a Medusa application, you get a fully-fledged commerce platform with a Framework for customization. The Medusa application's commerce features are built around [Commerce Modules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/index.html.md), which are available out-of-the-box. These features include cart and order management capabilities.
+
+You can customize the Medusa application and storefront to add a gift message to items in the cart. This feature allows customers to add a personalized message to their gifts, enhancing the shopping experience.
+
+## Summary
+
+By following this tutorial, you will learn how to:
+
+- Install and set up Medusa and the Next.js Starter Storefront.
+- Customize the storefront to support gift messages on cart items during checkout.
+- Customize the Medusa Admin to show gift items with messages in an order.
+
+You can follow this tutorial whether you're new to Medusa or an advanced Medusa developer.
+
+[View on Github](https://github.com/medusajs/examples/tree/main/order-gift-message): Find the full code for this tutorial.
+
+***
+
+## Step 1: Install a Medusa Application
+
+### Prerequisites
+
+- [Node.js v20+](https://nodejs.org/en/download)
+- [Git CLI tool](https://git-scm.com/downloads)
+- [PostgreSQL](https://www.postgresql.org/download/)
+
+Start by installing the Medusa application on your machine with the following command:
+
+```bash
+npx create-medusa-app@latest
+```
+
+First, you'll be asked for the project's name. Then, when prompted about installing the [Next.js Starter Storefront](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/nextjs-starter/index.html.md), choose "Yes."
+
+Afterward, the installation process will start, which will install the Medusa application in a directory with your project's name and the Next.js Starter Storefront in a separate directory named `{project-name}-storefront`.
+
+The Medusa application is composed of a headless Node.js server and an admin dashboard. The storefront is installed or custom-built separately and connects to the Medusa application through its REST endpoints, called [API routes](https://docs.medusajs.com/docs/learn/fundamentals/api-routes/index.html.md). Learn more in [Medusa's Architecture documentation](https://docs.medusajs.com/docs/learn/introduction/architecture/index.html.md).
+
+Once the installation finishes successfully, the Medusa Admin dashboard will open with a form to create a new user. Enter the user's credentials and submit the form. Afterward, you can log in with the new user and explore the dashboard.
+
+Check out the [troubleshooting guides](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/troubleshooting/create-medusa-app-errors/index.html.md) for help.
+
+***
+
+## Step 2: Add Gift Inputs to Cart Item
+
+In this step, you'll customize the Next.js Starter Storefront to allow customers to specify that an item is a gift and add a gift message to it.
+
+You'll store the gift option and message in the cart item's `metadata` property, which is a key-value `jsonb` object that can hold any additional information about the item. When the customer places the order, the `metadata` is copied to the `metadata` of the order's line items.
+
+So, you only need to customize the storefront to add the gift message input and update the cart item metadata.
+
+### a. Changes to Update Item Function
+
+The Next.js Starter Storefront has an `updateLineItem` function that sends a request to the Medusa server to update the cart item. However, it doesn't support updating the `metadata` property.
+
+So, in `src/lib/data/cart.ts`, find the `updateLineItem` function and add a `metadata` property to its object parameter:
+
+```ts title="src/lib/data/cart.ts" badgeLabel="Storefront" badgeColor="blue" highlights={[["4"], ["8"]]}
+export async function updateLineItem({
+ lineId,
+ quantity,
+ metadata,
+}: {
+ lineId: string
+ quantity: number
+ metadata?: Record
+}) {
+ // ...
+}
+```
+
+Next, change the usage of `await sdk.store.cart.updateLineItem` in the function to pass the `metadata` property:
+
+```ts title="src/lib/data/cart.ts" badgeLabel="Storefront" badgeColor="blue"
+const updateData: any = { quantity }
+if (metadata) {
+ updateData.metadata = metadata
+}
+
+await sdk.store.cart
+ .updateLineItem(cartId, lineId, updateData, {}, headers)
+// ...
+```
+
+You pass the `metadata` property to the Medusa server, which will update the cart item with the new metadata.
+
+### b. Add Gift Inputs
+
+Next, you'll modify the cart item component that's shown in the cart and checkout pages to show two inputs: one to specify that the item is a gift and another to add a gift message.
+
+In `src/modules/cart/components/item/index.tsx`, add the following imports at the top of the file:
+
+```tsx title="src/modules/cart/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue"
+import { Checkbox, Textarea, Button, Label } from "@medusajs/ui"
+```
+
+You import components from the [Medusa UI library](https://docs.medusajs.com/ui/index.html.md) that will be useful for the gift inputs.
+
+Next, in the `Item` component, add the following variables before the `changeQuantity` function:
+
+```tsx title="src/modules/cart/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue" highlights={giftVarsHighlights}
+const [giftUpdating, setGiftUpdating] = useState(false)
+const [newGiftMessage, setNewGiftMessage] = useState(
+ item.metadata?.gift_message as string || ""
+)
+const [isEditingGiftMessage, setIsEditingGiftMessage] = useState(false)
+
+const isGift = item.metadata?.is_gift === "true"
+const giftMessage = item.metadata?.gift_message as string
+```
+
+You define the following variables:
+
+- `giftUpdating`: A state variable to track whether the gift message is being updated. This will be useful to handle loading and disabled states.
+- `newGiftMessage`: A state variable to hold the new gift message input value.
+- `isEditingGiftMessage`: A state variable to track whether the gift message input is being edited. This will be useful to show or hide the input field.
+- `isGift`: A boolean indicating whether the item is a gift based on the `metadata.is_gift` property.
+- `giftMessage`: The current gift message from the item's `metadata.gift_message` property.
+
+Next, add the following functions before the `return` statement to handle updates to the gift inputs:
+
+```tsx title="src/modules/cart/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue" highlights={giftFunctionsHighlights}
+const handleGiftToggle = async (checked: boolean) => {
+ setGiftUpdating(true)
+
+ try {
+ const newMetadata = {
+ is_gift: checked.toString(),
+ gift_message: checked ? newGiftMessage : "",
+ }
+
+ await updateLineItem({
+ lineId: item.id,
+ quantity: item.quantity,
+ metadata: newMetadata,
+ })
+ } catch (error) {
+ console.error("Error updating gift status:", error)
+ } finally {
+ setGiftUpdating(false)
+ }
+}
+
+const handleSaveGiftMessage = async () => {
+ setGiftUpdating(true)
+
+ try {
+ const newMetadata = {
+ is_gift: "true",
+ gift_message: newGiftMessage,
+ }
+
+ await updateLineItem({
+ lineId: item.id,
+ quantity: item.quantity,
+ metadata: newMetadata,
+ })
+ setIsEditingGiftMessage(false)
+ } catch (error) {
+ console.error("Error updating gift message:", error)
+ } finally {
+ setGiftUpdating(false)
+ }
+}
+
+const handleStartEdit = () => {
+ setIsEditingGiftMessage(true)
+}
+
+const handleCancelEdit = () => {
+ setNewGiftMessage(giftMessage || "")
+ setIsEditingGiftMessage(false)
+}
+```
+
+You define the following functions:
+
+- `handleGiftToggle`: Used when the gift checkbox is toggled. It updates the cart item's metadata to set the `is_gift` and `gift_message` properties based on the checkbox state.
+- `handleSaveGiftMessage`: Used to save the gift message when the customer clicks the "Save" button. It updates the cart item's metadata with the new gift message.
+- `handleStartEdit`: Used to start editing the gift message input by setting the `isEditingGiftMessage` state to `true`.
+- `handleCancelEdit`: Used to cancel the gift message editing and reset the input value to the current gift message.
+
+Finally, you'll change the `return` statement to include the gift inputs. Replace the existing return statement with the following:
+
+```tsx title="src/modules/cart/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue"
+return (
+
+)
+```
+
+You replace the previous table row design with a card. In the card, you show the item's image, title, variant options, quantity, and price.
+
+You also show a checkbox to toggle the gift status of the item. If the item is a gift, you show a text area to add or edit the gift message. You only show the gift message input if the user clicks an "Add" or "Edit" button.
+
+The gift message input has a "Save" button to save the message and a "Cancel" button to cancel the editing.
+
+### c. Update Cart and Checkout Templates
+
+The items are previously shown on the cart and checkout pages in a table. However, since you've changed the item component to a card, you'll need to update the cart and checkout templates to replace the table with a list of items.
+
+In `src/modules/cart/templates/items.tsx`, which shows the items on the cart page, change the `return` statement to the following:
+
+```tsx title="src/modules/cart/templates/items.tsx" badgeLabel="Storefront" badgeColor="blue"
+return (
+
+)
+```
+
+You replace the table that was wrapping the items with a `div` that contains a list of `Item` components.
+
+Next, in `src/modules/cart/templates/preview.tsx` that shows the items in the checkout summary, change the `return` statement to the following:
+
+```tsx title="src/modules/cart/templates/preview.tsx" badgeLabel="Storefront" badgeColor="blue"
+return (
+
+)
+```
+
+Similarly, you replace the table that was wrapping the items with a `div` that contains a list of `Item` components.
+
+### Test the Changes
+
+You can now test the gift inputs during checkout.
+
+First, start the Medusa application by running the following command in the Medusa application directory:
+
+```bash npm2yarn badgeLabel="Medusa Application" badgeColor="green"
+npm run dev
+```
+
+Then, start the Next.js Starter Storefront by running the following command in the storefront directory:
+
+```bash npm2yarn badgeLabel="Storefront" badgeColor="blue"
+npm run dev
+```
+
+Open the storefront in your browser at `http://localhost:8000`. Add a product to the cart, and proceed to the checkout page. You'll find a checkbox to mark the item as a gift for each item.
+
+
+
+If you check the box, you can also add and edit the gift message. The gift message will be saved in the cart item's `metadata`.
+
+
+
+***
+
+## Step 3: Show Gift Options in Order Confirmation Page
+
+Next, you'll customize the storefront to show the gift message of items in the order confirmation page.
+
+In `src/modules/order/components/item/index.tsx`, add in the `Item` component the following variables:
+
+```tsx title="src/modules/order/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue"
+const isGift = item.metadata?.is_gift === "true"
+const giftMessage = item.metadata?.gift_message as string
+```
+
+You define the following variables:
+
+- `isGift`: A boolean indicating whether the item is a gift based on the `metadata.is_gift` property.
+- `giftMessage`: The item's gift message from the `metadata.gift_message` property.
+
+Next, in the `return` statement, add the following below the `LineItemOptions` component:
+
+```tsx title="src/modules/order/components/item/index.tsx" badgeLabel="Storefront" badgeColor="blue"
+{isGift &&
+ Gift Message: {giftMessage || "No gift message provided"}
+}
+```
+
+If the item is a gift, you show the gift message below the variant options. If no gift message is provided, you show "No gift message provided."
+
+### Test the Changes
+
+To test this change, place an order with a gift item. On the order confirmation page, you should see the gift message displayed below the variant options.
+
+
+
+***
+
+## Step 4: Show Gift Options in Admin Dashboard
+
+In this step, you'll customize the Medusa Admin dashboard to show the gift items with their messages in an order.
+
+### What is a Widget?
+
+The Medusa Admin dashboard's pages are customizable to insert [widgets](https://docs.medusajs.com/docs/learn/fundamentals/admin/widgets/index.html.md) of custom content in predefined injection zones. You create these widgets as React components that allow admin users to perform custom actions.
+
+So, to show the gift items with their messages in an order, you'll create a custom widget that shows the gift items in the order details page.
+
+### Create the Widget
+
+You create a widget in a `.tsx` file under the `src/admin/widgets` directory. So, in the Medusa application directory, create the file `src/admin/widgets/order-gift-items-widget.tsx` with the following content:
+
+```tsx title="src/admin/widgets/order-gift-items-widget.tsx" badgeLabel="Medusa Application" badgeColor="green"
+import { defineWidgetConfig } from "@medusajs/admin-sdk"
+import { Container, Text } from "@medusajs/ui"
+import { DetailWidgetProps, AdminOrder } from "@medusajs/framework/types"
+
+const OrderGiftItemsWidget = ({ data }: DetailWidgetProps) => {
+ const giftItems = data.items?.filter(
+ (item: any) => item.metadata?.is_gift === "true"
+ )
+
+ if (!giftItems?.length) {
+ return null
+ }
+
+ return (
+
+ Gift Items & Messages
+
+
+ )
+}
+
+export const config = defineWidgetConfig({
+ zone: "order.details.side.after",
+})
+
+export default OrderGiftItemsWidget
+```
+
+A widget file must export:
+
+- A React component that renders the widget content.
+- A configuration object created with `defineWidgetConfig` that defines the widget's [injection zone](https://docs.medusajs.com/admin-widget-injection-zones/index.html.md).
+
+You define the `OrderGiftItemsWidget` component that is injected in the `order.details.side.after` zone. Because it's injected in the order details page, it receives the order details as a `data` prop.
+
+In the component, you filter the order items to get only the gift items by checking if the `metadata.is_gift` property is set to `"true"`. Then, you render the gift items with their messages in a new "Gift Items & Messages" section.
+
+### Test Medusa Admin Changes
+
+To test out the Medusa Admin widget, start the Medusa application by running the following command in the Medusa application directory:
+
+```bash npm2yarn badgeLabel="Medusa Application" badgeColor="green"
+npm run dev
+```
+
+Then, open the Medusa Admin at `http://localhost:9000/app` and log in with the user you created earlier.
+
+Go to the Orders page and click on an order that has gift items. You'll find a new section called "Gift Items & Messages" that shows the gift items with their messages.
+
+
+
+***
+
+## Optional: Handle Gift Items in Fulfillment Provider
+
+If you have a custom fulfillment provider and you want to handle gift items in it, you can do so in the `createFulfillment` method of the [Fulfillment Module Provider's service](https://docs.medusajs.com/references/fulfillment/provider/index.html.md).
+
+For example:
+
+```ts title="Fulfillment Module Provider's Service" badgeLabel="Medusa Application" badgeColor="green" highlights={createFulfillmentHighlights}
+class ManualFulfillmentService extends utils_1.AbstractFulfillmentProviderService {
+ // ...
+ async createFulfillment(
+ data: Record,
+ items: Partial>[],
+ order: Partial | undefined,
+ fulfillment: Partial>
+ ): Promise {
+ const itemsWithGiftMessage = order.items?.filter((lineItem) => {
+ const isInFulfillment = items.find(
+ (item) => item.line_item_id === lineItem.id
+ )
+ if (!isInFulfillment) {
+ return false
+ }
+ return lineItem.metadata?.is_gift === "true"
+ })
+
+ // TODO pass gift items to third-party provider
+ }
+}
+```
+
+You filter the order items to find the items that are part of the fulfillment and are gift items. You can then process or pass them differently to your third-party provider.
+
+***
+
+## Next Steps
+
+You've now added gift messages to items in carts and orders in Medusa.
+
+If you're new to Medusa, check out the [main documentation](https://docs.medusajs.com/docs/learn/index.html.md), where you'll get a more in-depth understanding of all the concepts you've used in this guide and more.
+
+To learn more about the commerce features that Medusa provides, check out Medusa's [Commerce Modules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/index.html.md).
+
+### Troubleshooting
+
+If you encounter issues during your development, check out the [troubleshooting guides](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/troubleshooting/index.html.md).
+
+### Getting Help
+
+If you encounter issues not covered in the troubleshooting guides:
+
+1. Visit the [Medusa GitHub repository](https://github.com/medusajs/medusa) to report issues or ask questions.
+2. Join the [Medusa Discord community](https://discord.gg/medusajs) for real-time support from community members.
+
+
# Implement Loyalty Points System in Medusa
In this tutorial, you'll learn how to implement a loyalty points system in Medusa.
diff --git a/www/apps/book/public/llms.txt b/www/apps/book/public/llms.txt
index f2b29f3ce8..6e5e672189 100644
--- a/www/apps/book/public/llms.txt
+++ b/www/apps/book/public/llms.txt
@@ -12,6 +12,8 @@ Medusa is for businesses and teams looking for a digital commerce platform with
Businesses of all sizes can use Medusa, from small start ups to large enterprises. Also, technical teams of all sizes can build with Medusa; all it takes is a developer to manage and deploy Medusa projects.
+> When searching for Medusa documentation, append `index.html.md` to the end of the URL to get a plain-text version of the document.
+
## Docs
- [Get Started](https://docs.medusajs.com/learn/installation/index.html.md): Install a digital commerce application with Medusa.
@@ -55,12 +57,85 @@ Businesses of all sizes can use Medusa, from small start ups to large enterprise
## Guides
- [Build a Brands Module](https://docs.medusajs.com/learn/customization/custom-features/index.html.md): Customize Medusa by building a Brand Module.
-- [Storefront Development](https://docs.medusajs.com/resources/storefront-development/index.html.md): Guides to build a storefront from scratch.
- [Admin Components](https://docs.medusajs.com/resources/admin-components/index.html.md): Components you can use in your admin customizations to build widgets and routes that match the Medusa Admin's design system.
- [Examples](https://docs.medusajs.com/resources/examples/index.html.md): Examples and code snippets of how to use different Medusa concepts.
- [Recipes](https://docs.medusajs.com/resources/recipes/index.html.md): Learn how to build common commerce use cases, such as marketplace and subscription-based purchases, with Medusa.
- [Deployment Guides](https://docs.medusajs.com/resources/deployment/index.html.md): Deploy to Medusa Cloud or self-host Medusa.
+## Storefront Development
+
+- [Storefront Development Tips](https://docs.medusajs.com/resources/storefront-development/tips/index.html.md): Tips and best practices for building storefronts with Medusa.
+- [Use a Publishable API Key in the Storefront](https://docs.medusajs.com/resources/storefront-development/publishable-api-keys/index.html.md): Learn how to use publishable API keys to scope API requests to sales channels.
+
+### Products
+
+- [Products in Storefront](https://docs.medusajs.com/resources/storefront-development/products/index.html.md): Learn how to display and manage products in your storefront.
+- [Show Products in Storefront](https://docs.medusajs.com/resources/storefront-development/products/list/index.html.md): Learn how to retrieve and display a list of products.
+- [Retrieve a Product in Storefront](https://docs.medusajs.com/resources/storefront-development/products/retrieve/index.html.md): Learn how to retrieve and display a single product's details.
+- [Select Product Variants in Storefront](https://docs.medusajs.com/resources/storefront-development/products/variants/index.html.md): Learn how to handle product variant selection in your storefront.
+- [Retrieve Product Variant's Prices in Storefront](https://docs.medusajs.com/resources/storefront-development/products/price/index.html.md): Learn how to retrieve and display product variant prices.
+- [Retrieve Product Variant's Inventory in Storefront](https://docs.medusajs.com/resources/storefront-development/products/inventory/index.html.md): Learn how to check product variant inventory availability.
+
+### Product Categories
+
+- [Product Categories in Storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/index.html.md): Learn how to work with product categories in your storefront.
+- [Show Product Categories in Storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/list/index.html.md): Learn how to retrieve and display product categories.
+- [Retrieve a Category in Storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/retrieve/index.html.md): Learn how to retrieve and display a specific category.
+- [Retrieve Nested Categories in Storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/nested-categories/index.html.md): Learn how to handle nested category structures.
+- [Retrieve a Category's Products in Storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/products/index.html.md): Learn how to retrieve products that belong to a specific category.
+
+### Product Collections
+
+- [Product Collections in Storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/index.html.md): Learn how to work with product collections in your storefront.
+- [List Product Collections in Storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/list/index.html.md): Learn how to retrieve and display product collections.
+- [Retrieve a Collection in Storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/retrieve/index.html.md): Learn how to retrieve and display a specific collection.
+- [Retrieve a Collection's Products in Storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/products/index.html.md): Learn how to retrieve products that belong to a specific collection.
+
+### Cart Management
+
+- [Carts in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/index.html.md): Learn how to manage shopping carts in your storefront.
+- [Create Cart in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/create/index.html.md): Learn how to create a new shopping cart.
+- [Retrieve Cart in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/retrieve/index.html.md): Learn how to retrieve an existing cart.
+- [Update Cart in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/update/index.html.md): Learn how to update cart information.
+- [Manage Cart's Items in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items/index.html.md): Learn how to add, update, and remove items from a cart.
+- [Show Cart Totals](https://docs.medusajs.com/resources/storefront-development/cart/totals/index.html.md): Learn how to calculate and display cart totals.
+- [Create Cart Context in Storefront](https://docs.medusajs.com/resources/storefront-development/cart/context/index.html.md): Learn how to create a React context for cart management.
+
+### Checkout Process
+
+- [Checkout in Storefront](https://docs.medusajs.com/resources/storefront-development/checkout/index.html.md): Learn how to implement the complete checkout process.
+- [Checkout Step 1: Enter Email](https://docs.medusajs.com/resources/storefront-development/checkout/email/index.html.md): Learn how to implement the email entry step in checkout.
+- [Checkout Step 2: Set Shipping and Billing Addresses](https://docs.medusajs.com/resources/storefront-development/checkout/address/index.html.md): Learn how to handle address collection in checkout.
+- [Checkout Step 3: Choose Shipping Method](https://docs.medusajs.com/resources/storefront-development/checkout/shipping/index.html.md): Learn how to implement shipping method selection.
+- [Checkout Step 4: Choose Payment Provider](https://docs.medusajs.com/resources/storefront-development/checkout/payment/index.html.md): Learn how to implement payment provider selection.
+- [Payment with Stripe in React Storefront](https://docs.medusajs.com/resources/storefront-development/checkout/payment/stripe/index.html.md): Learn how to integrate Stripe payments in your React storefront.
+- [Checkout Step 5: Complete Cart](https://docs.medusajs.com/resources/storefront-development/checkout/complete-cart/index.html.md): Learn how to complete the checkout process.
+- [Order Confirmation in Storefront](https://docs.medusajs.com/resources/storefront-development/checkout/order-confirmation/index.html.md): Learn how to display order confirmation to customers.
+
+### Customer Management
+
+- [Customers in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/index.html.md): Learn how to manage customer accounts in your storefront.
+- [Customer Context in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/context/index.html.md): Learn how to create a React context for customer management.
+- [Register Customer in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/register/index.html.md): Learn how to implement customer registration.
+- [Login Customer in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/login/index.html.md): Learn how to implement customer login functionality.
+- [Third-Party or Social Login in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/third-party-login/index.html.md): Learn how to implement social login options.
+- [Retrieve Logged-In Customer in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/retrieve/index.html.md): Learn how to retrieve customer information.
+- [Edit Customer Profile in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/profile/index.html.md): Learn how to allow customers to edit their profiles.
+- [Manage Customer Addresses in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses/index.html.md): Learn how to manage customer shipping and billing addresses.
+- [Reset Customer Password in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/reset-password/index.html.md): Learn how to implement password reset functionality.
+- [Log-out Customer in Storefront](https://docs.medusajs.com/resources/storefront-development/customers/log-out/index.html.md): Learn how to implement customer logout functionality.
+
+### Regions
+
+- [Regions in Storefront](https://docs.medusajs.com/resources/storefront-development/regions/index.html.md): Learn how to handle multi-region support in your storefront.
+- [List Regions in Storefront](https://docs.medusajs.com/resources/storefront-development/regions/list/index.html.md): Learn how to retrieve and display available regions.
+- [Store Selected Region in Storefront](https://docs.medusajs.com/resources/storefront-development/regions/store-retrieve-region/index.html.md): Learn how to persist and retrieve the selected region.
+- [Region React Context in Storefront](https://docs.medusajs.com/resources/storefront-development/regions/context/index.html.md): Learn how to create a React context for region management.
+
+### Advanced Guides
+
+- [Implement Express Checkout with Medusa](https://docs.medusajs.com/resources/storefront-development/guides/express-checkout/index.html.md): Learn how to implement a streamlined express checkout flow.
+
## API Reference
- [Admin Authentication](https://docs.medusajs.com/api/admin#authentication): Send authenticated requests as an admin user.
@@ -268,16 +343,45 @@ Businesses of all sizes can use Medusa, from small start ups to large enterprise
- [Notification Module Provider](https://docs.medusajs.com/resources/infrastructure-modules/notification/index.html.md): A notification module provider implements the underlying logic of sending notification. It either integrates a third-party service or uses custom logic to send the notification.
- [Workflow Engine Modules](https://docs.medusajs.com/resources/infrastructure-modules/workflow-engine/index.html.md): Workflow engine modules handle tracking and recording the transactions and statuses of workflows and their steps.
+## Integration Guides
+
+- [Algolia](https://docs.medusajs.com/resources/integrations/guides/algolia/index.html.md): Learn how to integrate Algolia with Medusa and add search functionalities.
+- [Contentful](https://docs.medusajs.com/resources/integrations/guides/contentful/index.html.md): Learn how to integrate Contentful with Medusa and add localization to your Medusa store.
+- [Magento](https://docs.medusajs.com/resources/integrations/guides/magento/index.html.md): Learn how to migrate your products and categories from Magento to Medusa.
+- [Mailchimp](https://docs.medusajs.com/resources/integrations/guides/mailchimp/index.html.md): Learn how to integrate Mailchimp into Medusa and send notifications like newsletters.
+- [Resend](https://docs.medusajs.com/resources/integrations/guides/resend/index.html.md): Learn how to integrate Resend into Medusa and send notifications, such as order-confirmation emails.
+- [Sanity](https://docs.medusajs.com/resources/integrations/guides/sanity/index.html.md): Learn how to integrate Sanity into Medusa to use rich CMS capabilities.
+- [Segment](https://docs.medusajs.com/resources/integrations/guides/segment/index.html.md): Learn how to integrate Segment into Medusa to track events and user behavior.
+- [Sentry](https://docs.medusajs.com/resources/integrations/guides/sentry/index.html.md): Learn how to integrate Senrty into Medusa to monitor performance and track errors.
+- [ShipStation](https://docs.medusajs.com/resources/integrations/guides/shipstation/index.html.md): Learn how to integrate ShipStation into Medusa to fulfill orders.
+- [Slack](https://docs.medusajs.com/resources/integrations/guides/slack/index.html.md): Learn how to integrate Slack into Medusa to send notifications, such as new-order notifications.
+
+## Tutorials
+
+- [Use Saved Payment Methods During Checkout](https://docs.medusajs.com/resources/tutorials/saved-payment-methods/index.html.md): Learn how to allow customers to save their payment methods and use them for future purchases.
+- [Implement Product Reviews in Medusa](https://docs.medusajs.com/resources/tutorials/product-reviews/index.html.md): Learn how to implement a product review system with ratings and comments.
+- [Add Gift Message to Line Items in Medusa](https://docs.medusajs.com/resources/tutorials/gift-message/index.html.md): Learn how to add gift message functionality to line items in orders.
+- [Send Abandoned Cart Notifications in Medusa](https://docs.medusajs.com/resources/tutorials/abandoned-cart/index.html.md): Learn how to implement abandoned cart email notifications to recover lost sales.
+- [Implement Loyalty Points System in Medusa](https://docs.medusajs.com/resources/tutorials/loyalty-points/index.html.md): Learn how to build a customer loyalty points system with rewards.
+- [Implement Quick Re-Order Functionality in Medusa](https://docs.medusajs.com/resources/tutorials/re-order/index.html.md): Learn how to allow customers to quickly reorder their previous purchases.
+- [Implement Phone Authentication and Integrate Twilio SMS](https://docs.medusajs.com/resources/tutorials/phone-auth/index.html.md): Learn how to implement phone number authentication using Twilio SMS verification.
+- [Implement First-Purchase Discount in Medusa](https://docs.medusajs.com/resources/tutorials/first-purchase-discounts/index.html.md): Learn how to create automatic discounts for first-time customers.
+- [Marketplace Recipe: Vendors Example](https://docs.medusajs.com/resources/recipes/marketplace/examples/vendors/index.html.md): Learn how to build a marketplace with multiple vendors, vendor admins, and order splitting.
+- [Marketplace Recipe: Restaurant Delivery Example](https://docs.medusajs.com/resources/recipes/marketplace/examples/restaurant-delivery/index.html.md): Learn how to build a restaurant delivery marketplace with location-based ordering.
+- [Create Wishlist Plugin](https://docs.medusajs.com/resources/plugins/guides/wishlist/index.html.md): Learn how to build a wishlist plugin.
+
## Optional
- [Medusa Configurations](https://docs.medusajs.com/resources/references/medusa-config/index.html.md): Configure the Medusa application for your use case.
- [Troubleshooting Guides](https://docs.medusajs.com/resources/troubleshooting/index.html.md): Find solutions for common problems you face during your development.
- [Admin Widget Injection Zones](https://docs.medusajs.com/resources/admin-widget-injection-zones/index.html.md): List of zones you can inject admin widgets into.
- [Medusa Container Resources](https://docs.medusajs.com/resources/medusa-container-resources/index.html.md): List of resources or dependencies you can resolve from the Medusa container.
-- [Events List](https://docs.medusajs.com/resources/references/events/index.html.md): List of events you can listen to in a subscriber.
+- [Events Reference](https://docs.medusajs.com/resources/references/events/index.html.md): List of events you can listen to in a subscriber.
- [Workflows SDK Reference](https://docs.medusajs.com/resources/references/workflows/index.html.md): A reference to the SDK to create workflows in your Medusa application.
- [DML Reference](https://docs.medusajs.com/resources/references/data-model/index.html.md): A reference to Medusa's data-modeling language.
+- [Data Model Repository Reference](https://docs.medusajs.com/resources/data-model-repository-reference/index.html.md): A reference to the repository generated for data models.
- [Service Factory Reference](https://docs.medusajs.com/resources/service-factory-reference/index.html.md): A reference to the methods generated by the service factory.
- [Helper Steps Reference](https://docs.medusajs.com/resources/references/helper-steps/index.html.md): A reference to the helper steps you can use in your custom workflows.
- [Core Workflows Reference](https://docs.medusajs.com/resources/medusa-workflows-reference/index.html.md): A reference to all workflows and steps provided by Medusa.
- [Testing Framework Reference](https://docs.medusajs.com/resources/test-tools-reference/index.html.md): A reference to Medusa's testing framework toolkit.
+- [Full Documentation file](https://docs.medusajs.com/llms-full.txt): An llms-full.txt file that holds the entire documentation in plain text.
\ No newline at end of file
diff --git a/www/apps/book/sidebar.mjs b/www/apps/book/sidebar.mjs
index 198b48e481..d021d47117 100644
--- a/www/apps/book/sidebar.mjs
+++ b/www/apps/book/sidebar.mjs
@@ -23,6 +23,11 @@ export const sidebars = [
title: "Architecture",
path: "/learn/introduction/architecture",
},
+ {
+ type: "link",
+ title: "AI Assistants and LLMs",
+ path: "/learn/introduction/build-with-llms-ai",
+ },
],
},
{