docs: Fix typos in productsCreated hook (#11276)

This commit is contained in:
Martin Repta
2025-02-13 03:37:34 +11:00
committed by GitHub
parent d9946e679d
commit 1b6d8b9f7a
3 changed files with 7 additions and 7 deletions

View File

@@ -178,7 +178,7 @@ export const createProductsWorkflowId = "create-products"
*
* Create one or more products with options and variants.
*
* @property hooks.productCreated - This hook is executed after the products are created. You can consume this hook to perform custom actions on the created products.
* @property hooks.productsCreated - This hook is executed after the products are created. You can consume this hook to perform custom actions on the created products.
*/
export const createProductsWorkflow = createWorkflow(
createProductsWorkflowId,

View File

@@ -36,7 +36,7 @@ To learn more about the `additional_data` property and the API routes that accep
---
## 1. Consume the productCreated Hook
## 1. Consume the productsCreated Hook
A workflow hook is a point in a workflow where you can inject a step to perform a custom functionality. Consuming a workflow hook allows you to extend the features of a workflow and, consequently, the API route that uses it.
@@ -84,7 +84,7 @@ createProductsWorkflow.hooks.productsCreated(
)
```
Workflows have a special `hooks` property to access its hooks and consume them. Each hook, such as `productCreated`, accepts a step function as a parameter. The step function accepts the following parameters:
Workflows have a special `hooks` property to access its hooks and consume them. Each hook, such as `productsCreated`, accepts a step function as a parameter. The step function accepts the following parameters:
1. An object having an `additional_data` property, which is the custom data passed in the request body under `additional_data`. The object will also have properties passed from the workflow to the hook, which in this case is the `products` property that holds an array of the created products.
2. An object of properties related to the step's context. It has a `container` property whose value is the [Medusa container](../../../fundamentals/medusa-container/page.mdx) to resolve framework and commerce tools.
@@ -101,7 +101,7 @@ Learn more about Link in [this chapter](../../../fundamentals/module-links/link/
</Note>
To use Link in the `productCreated` hook, replace the `TODO` with the following:
To use Link in the `productsCreated` hook, replace the `TODO` with the following:
export const hook2Highlights = [
["1", `"link"`, "Resolve Link from the container."]
@@ -169,7 +169,7 @@ In the compensation function, if the `links` parameter isn't empty, you resolve
## 2. Configure Additional Data Validation
Now that you've consumed the `productCreated` hook, you want to configure the `/admin/products` API route that creates a new product to accept a brand ID in its `additional_data` parameter.
Now that you've consumed the `productsCreated` hook, you want to configure the `/admin/products` API route that creates a new product to accept a brand ID in its `additional_data` parameter.
You configure the properties accepted in `additional_data` in the `src/api/middlewares.ts` that exports middleware configurations. So, create the file (or, if already existing, add to the file) `src/api/middlewares.ts` the following content:

View File

@@ -85,8 +85,8 @@ For example:
```ts title="src/workflows/hooks/product-created.ts"
import { createProductsWorkflow } from "@medusajs/medusa/core-flows"
createProductsWorkflow.hooks.productCreated(
async ({ productId }, { container }) => {
createProductsWorkflow.hooks.productsCreated(
async ({ products }, { container }) => {
// TODO perform an action
return new StepResponse(undefined, { ids })