From 1b6d8b9f7a679ba82060364fc89a528f648aa19e Mon Sep 17 00:00:00 2001 From: Martin Repta Date: Thu, 13 Feb 2025 03:37:34 +1100 Subject: [PATCH] docs: Fix typos in productsCreated hook (#11276) --- .../core-flows/src/product/workflows/create-products.ts | 2 +- .../extend-features/extend-create-product/page.mdx | 8 ++++---- .../learn/fundamentals/workflows/workflow-hooks/page.mdx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/core-flows/src/product/workflows/create-products.ts b/packages/core/core-flows/src/product/workflows/create-products.ts index 3a7911cfc5..ea1796a0c8 100644 --- a/packages/core/core-flows/src/product/workflows/create-products.ts +++ b/packages/core/core-flows/src/product/workflows/create-products.ts @@ -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, diff --git a/www/apps/book/app/learn/customization/extend-features/extend-create-product/page.mdx b/www/apps/book/app/learn/customization/extend-features/extend-create-product/page.mdx index 717a81586b..6a0b5c7659 100644 --- a/www/apps/book/app/learn/customization/extend-features/extend-create-product/page.mdx +++ b/www/apps/book/app/learn/customization/extend-features/extend-create-product/page.mdx @@ -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/ -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: diff --git a/www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx b/www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx index a31216d5ed..9b894c92d8 100644 --- a/www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx +++ b/www/apps/book/app/learn/fundamentals/workflows/workflow-hooks/page.mdx @@ -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 })