Raw
1 ---
2 products:
3 - product
4 - order
5 ---
6
7 import { ChildDocs } from "docs-ui"
8 import { AcademicCapSolid } from "@medusajs/icons"
9
10 export const metadata = {
11 title: `Marketplace Recipe`,
12 }
13
14 # {metadata.title}
15
16 This recipe provides the general steps to implement a marketplace in your Medusa application.
17
18 ## Example Guides
19
20 <ChildDocs type="item" onlyTopLevel={true} />
21
22 ## Overview
23
24 A marketplace is an online commerce store that allows different vendors to sell their products within the same commerce system. Customers can purchase products from any of these vendors, and vendors can manage their orders separately.
25
26 The Medusa [Framework](!docs!/learn/fundamentals/framework) built for customizations facilitates building a marketplace. You can create a Marketplace Module that implements custom data models, such as vendors or sellers, and link those data models to existing ones such as products and orders. You also expose custom features using API routes, and implement complex flows using workflows.
27
28 <Note title="Related use-case">
29
30 [How Foraged built a custom marketplace with Medusa](https://medusajs.com/blog/foraged/).
31
32 </Note>
33
34 ---
35
36 ## Create Custom Module with Data Models
37
38 In a marketplace, a business or a vendor has a user, and they can use that user to authenticate and manage the vendor's data.
39
40 You can create a marketplace module that implements data models for vendors, their admins, and any other data models that fit your use case.
41
42 <CardList items={[
43 {
44 href: "!docs!/learn/fundamentals/modules",
45 title: "Create a Module",
46 text: "Learn how to create a module.",
47 icon: AcademicCapSolid,
48 },
49 {
50 href: "!docs!/learn/fundamentals/modules#1-create-data-model",
51 title: "Create Data Models",
52 text: "Create data models in the module.",
53 icon: AcademicCapSolid,
54 },
55 ]} />
56
57 ---
58
59 ## Link Custom and Existing Data Models
60
61 Since a vendor has products, orders, and other models based on your use case, you can define module links between your module's data models and the Commerce Module's data models.
62
63 For example, if you defined a vendor data model in a marketplace module, you can define a module link between the vendor and the Product Module's product data model. This builds an association between a vendor and their products, allowing you to query and manage products based on the vendor.
64
65 <Card
66 href="!docs!/learn/fundamentals/module-links"
67 title="Define a Module Link"
68 text="Learn how to define a module link."
69 icon={AcademicCapSolid}
70 />
71
72 ---
73
74 ## Create Vendor API Routes
75
76 Your marketplace will most likely provide custom features for vendors, such as managing their products and orders. You can create API routes that expose these features to the vendors.
77
78 When you build these API routes, it's essential that you protect them to only allow authenticated vendors. For example, only a vendor's admin should be able to manage their products and orders.
79
80 Medusa supports creating custom actor types that can be authenticated with your custom API routes.
81
82 <CardList items={[
83 {
84 href: "!docs!/learn/fundamentals/api-routes",
85 title: "Create API Routes",
86 text: "Learn how to create an API Route in Medusa.",
87 icon: AcademicCapSolid,
88 },
89 {
90 href: "/commerce-modules/auth/create-actor-type",
91 title: "Create an Actor Type",
92 text: "Learn how to create an actor type and authenticate it.",
93 icon: AcademicCapSolid,
94 },
95 ]} />
96
97 ---
98
99 ## Split Orders Based on Vendors
100
101 If your use case allows a customer's orders to have items from different vendors, you can replicate the [Complete Cart API route](!api!/store/carts/complete-cart) to customize the order creation process.
102
103 In the API route, you can create a workflow that splits the order into multiple orders, one for each vendor. A workflow is a series of steps that provide features like rollback and retry mechanisms.
104
105 <CardList items={[
106 {
107 href: "!docs!/learn/fundamentals/api-routes/override",
108 title: "Replicate API Routes",
109 text: "Learn how to replicate an existing API route.",
110 icon: AcademicCapSolid,
111 },
112 {
113 href: "!docs!/learn/fundamentals/workflows",
114 title: "Create a Workflow",
115 text: "Learn how to create a workflow in Medusa.",
116 icon: AcademicCapSolid,
117 },
118 ]} />
119
120 ---
121
122 ## Customize Admin Dashboard
123
124 Based on your use case, you may need to customize the Medusa Admin to add new widgets or pages.
125
126 For example, you can create a page that lists all vendors or a widget that shows a product's vendor information.
127
128 The Medusa Admin is an extensible application within your Medusa application. You can customize it by:
129
130 - **Widgets**: Adding widgets to existing pages, such as the product page.
131 - **UI Routes**: Adding new pages to the Medusa Admin, such as a page to manage vendors.
132 - **Settings Pages**: Adding new pages to the Medusa Admin settings, such as a page to manage marketplace settings.
133
134 <CardList items={[
135 {
136 href: "!docs!/learn/fundamentals/admin/widgets",
137 title: "Create Admin Widget",
138 text: "Add widgets into existing admin pages.",
139 icon: AcademicCapSolid,
140 },
141 {
142 href: "!docs!/learn/fundamentals/admin/ui-routes",
143 title: "Create Admin UI Routes",
144 text: "Add new pages to your Medusa Admin.",
145 icon: AcademicCapSolid,
146 },
147 ]} />
148
149 <Card
150 href="!docs!/learn/fundamentals/admin/ui-routes#create-settings-page"
151 title="Create Admin Setting Page"
152 text="Add new page to the Medusa Admin settings."
153 icon={AcademicCapSolid}
154 className="mt-1"
155 />
156
157 ---
158
159 ## Build Dashboard for Vendors
160
161 For more complex use cases, customizing the Medusa Admin may not be enough to allow vendors to manage their data.
162
163 In that case, you can build a custom dashboard for vendors that allows them to manage their data. This dashboard can interact with Medusa's Admin API and the custom API routes you created for vendors to provide a seamless experience.
164
165 <Card
166 href="!api!/admin"
167 title="Medusa Admin APIs"
168 text="Learn about available APIs for the Medusa Admin."
169 icon={AcademicCapSolid}
170 />
171
172 ---
173
174 ## Customize or Build Storefront
175
176 Medusa provides a Next.js Starter Storefront to use with your application. You can customize it for your marketplace use case, such as showing products by vendor.
177
178 Alternatively, you can build your own storefront using the Medusa APIs. This headless approach gives you the flexibility to build a custom storefront without limitations on which tech stack you use, or the design of the storefront.
179
180 <CardList items={[
181 {
182 href: "/nextjs-starter",
183 title: "Next.js Starter Storefront",
184 text: "Learn how to install and customize the Next.js Starter Storefront.",
185 icon: AcademicCapSolid,
186 },
187 {
188 href: "/storefront-development",
189 title: "Storefront Development",
190 text: "Find useful guides for creating a custom storefront.",
191 icon: AcademicCapSolid,
192 },
193 ]} />