You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx
+21-23Lines changed: 21 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ export const metadata = {
4
4
5
5
# {metadata.title}
6
6
7
-
In this chapter, you'll learn what a workflow hook is and how to consume them.
7
+
In this chapter, you'll learn what workflow hooks are and how to use them.
8
8
9
9
## What is a Workflow Hook?
10
10
11
-
A workflow hook is a point in a workflow where you can inject custom functionality as a step function, called a hook handler.
11
+
A workflow hook is a specific point in a workflow where you can inject custom functionality. This custom functionality is called a hook handler.
12
12
13
13
Medusa exposes hooks in many of its workflows that are used in its API routes. You can consume those hooks to add your custom logic.
14
14
@@ -28,13 +28,13 @@ You want to perform a custom action during a workflow's execution, such as when
28
28
29
29
## How to Consume a Hook?
30
30
31
-
A workflow has a special `hooks` property which is an object that holds its hooks.
31
+
A workflow has a special `hooks` property. This property is an object that contains all available hooks.
32
32
33
33
So, in a TypeScript or JavaScript file created under the `src/workflows/hooks` directory:
34
34
35
-
-Importtheworkflow.
36
-
- Access its hook using the `hooks` property.
37
-
- Pass the hook a step function as a parameter to consume it.
35
+
1.Importtheworkflow.
36
+
2. Access the hook using the `hooks` property.
37
+
3. Pass a step function as a parameter to the hook.
38
38
39
39
For example, to consume the `productsCreated` hook of Medusa's `createProductsWorkflow`, create the file `src/workflows/hooks/product-created.ts` with the following content:
The `productsCreated` hook is available on the workflow's `hooks` property by its name.
55
+
The `productsCreated` hook is available in the workflow's `hooks` property.
56
56
57
-
You invoke the hook, passing a step function (the hook handler) as a parameter.
57
+
You call the hook and pass a step function (the hook handler) as a parameter.
58
58
59
-
Now, when a product is created using the [Create Product API route](!api!/admin#products_postproducts), your hook handler is executed after the product is created.
59
+
Now, when a product is created using the [Create Product API route](!api!/admin#products_postproducts), your hook handler runs after the product is created.
60
60
61
61
<Note>
62
62
63
-
A hook can have only one handler.
63
+
A hook can have only one handler. So, you can't consume the same hook multiple times.
64
64
65
65
</Note>
66
66
@@ -74,7 +74,9 @@ Refer to the [createProductsWorkflow reference](!resources!/references/medusa-wo
74
74
75
75
Since a hook handler is essentially a step function, it receives the hook's input as a first parameter, and an object holding a `container` property as a second parameter.
76
76
77
-
Each hook has different input. For example, the `productsCreated` hook receives an object having a `products` property holding the created product.
77
+
Each hook has different input. For example, the `productsCreated` hook receives an object with a `products` property that contains the created product.
78
+
79
+
You can find the input for each workflow's hooks in the [Core Workflows Reference](!resources!/medusa-workflows-reference).
Copy file name to clipboardExpand all lines: www/apps/book/app/learn/storefront-development/page.mdx
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,15 @@ export const metadata = {
6
6
7
7
# {metadata.title}
8
8
9
-
The Medusa application is made up of a Node.js server and an admin dashboard. Storefronts are installed, built, and hosted separately from the Medusa application, giving you the flexibility to choose the frontend tech stack that you and your team are proficient in, and implement unique design systems and user experience.
9
+
In this chapter, you'll learn about storefronts and how to build one.
10
10
11
-
You can build your storefront from scratch with your preferred tech stack, or start with our Next.js Starter storefront. The Next.js Starter storefront provides rich commerce features and a sleek design. Developers and businesses can use it as-is or build on top of it to tailor it for the business's unique use case, design, and customer experience.
11
+
## Storefronts in Medusa
12
+
13
+
The Medusa application includes a Node.js server and an admin dashboard. Storefronts are separate applications that you install, build, and host independently from Medusa. This gives you the flexibility to choose your preferred frontend tech stack and implement unique designs and user experiences.
14
+
15
+
In your storefront, you can retrieve data and perform commerce operations by sending requests to the Medusa application's [Store API routes](!api!/store) and your custom API routes.
16
+
17
+
You can build your storefront from scratch with your preferred tech stack, or start with our Next.js Starter storefront. The Next.js Starter storefront provides rich commerce features and a modern design. You can use it as-is or customize it to match your business needs, design requirements, and customer experience goals.
12
18
13
19
<CardList
14
20
items={[
@@ -25,12 +31,12 @@ You can build your storefront from scratch with your preferred tech stack, or st
25
31
26
32
---
27
33
28
-
## Passing a Publishable API Key in Storefront Requests
34
+
## Using a Publishable API Key in Storefront Requests
29
35
30
-
When sending a request to an API route starting with `/store`, you must include a publishable API key in the header of your request.
36
+
When sending requests to API routes that start with `/store`, you must include a publishable API key in the request header.
31
37
32
38
A publishable API key sets the scope of your request to one or more sales channels.
33
39
34
-
Then, when you retrieve products, only products of those sales channels are retrieved. This also ensures you retrieve correct inventory data, and associate created orders with the scoped sales channel.
40
+
When you retrieve products, only products from those sales channels are returned. This also ensures you get correct inventory data and associate created orders with the right sales channel.
35
41
36
-
Learn more about passing the publishable API key in [this storefront development guide](!resources!/storefront-development/publishable-api-keys).
42
+
Learn more about using the publishable API key in the [Storefront Development guide](!resources!/storefront-development/publishable-api-keys).
0 commit comments