docs: fixes to customization docs (#9236)
Closes #9225, #9224, #9226, #9227 Closes DOCS-948, DOCS-947, DOCS-945, DOCS-946
This commit is contained in:
@@ -77,17 +77,18 @@ The [createProductsWorkflow](!resources!/references/medusa-workflows/createProdu
|
||||
So, to consume the `productsCreated` hook, create the file `src/workflows/hooks/created-product.ts` with the following content:
|
||||
|
||||
export const hookHighlights = [
|
||||
["6", "productsCreated", "Access the hook in the `hooks` property."],
|
||||
["8", "", "Only proceed if the brand ID is passed in the additional data."],
|
||||
["17", "retrieveBrand", "Try to retrieve the brand to ensure it exists."],
|
||||
["21", "links", "Define an array to store the links in."],
|
||||
["25", "push", "Add a link to be created."],
|
||||
["35", "create", "Create the links."]
|
||||
["7", "productsCreated", "Access the hook in the `hooks` property."],
|
||||
["9", "", "Only proceed if the brand ID is passed in the additional data."],
|
||||
["18", "retrieveBrand", "Try to retrieve the brand to ensure it exists."],
|
||||
["27", "links", "Define an array to store the links in."],
|
||||
["31", "push", "Add a link to be created."],
|
||||
["41", "create", "Create the links."]
|
||||
]
|
||||
|
||||
```ts title="src/workflows/hooks/created-product.ts" highlights={hookHighlights}
|
||||
import { createProductsWorkflow } from "@medusajs/core-flows"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
import { StepResponse } from "@medusajs/workflows-sdk"
|
||||
import { Modules, ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { BRAND_MODULE } from "../../modules/brand"
|
||||
import BrandModuleService from "../../modules/brand/service"
|
||||
|
||||
@@ -104,7 +105,12 @@ createProductsWorkflow.hooks.productsCreated(
|
||||
// if the brand doesn't exist, an error is thrown.
|
||||
await brandModuleService.retrieveBrand(additional_data.brand_id as string)
|
||||
|
||||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||
const remoteLink = container.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
const logger = container.resolve(
|
||||
ContainerRegistrationKeys.LOGGER
|
||||
)
|
||||
|
||||
const links = []
|
||||
|
||||
@@ -122,8 +128,10 @@ createProductsWorkflow.hooks.productsCreated(
|
||||
|
||||
await remoteLink.create(links)
|
||||
|
||||
logger.info("Linked brand to products")
|
||||
|
||||
return new StepResponse(links, links)
|
||||
})
|
||||
})
|
||||
)
|
||||
```
|
||||
|
||||
@@ -139,8 +147,8 @@ Add the following compensation function as a second parameter:
|
||||
|
||||
```ts title="src/workflows/hooks/created-product.ts"
|
||||
createProductsWorkflow.hooks.productsCreated(
|
||||
// ...
|
||||
(async ({ links }, { container }) => {
|
||||
// ...
|
||||
(async (links, { container }) => {
|
||||
if (!links.length) {
|
||||
return
|
||||
}
|
||||
@@ -149,7 +157,7 @@ createProductsWorkflow.hooks.productsCreated(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
|
||||
await remoteLink.dimiss(links)
|
||||
await remoteLink.dismiss(links)
|
||||
})
|
||||
)
|
||||
```
|
||||
|
||||
@@ -112,7 +112,7 @@ Make sure to replace the email and password with your user's credentials.
|
||||
Then, send a `GET` request to `/admin/products/:id/brand`:
|
||||
|
||||
```bash
|
||||
curl 'http://localhost:9000/admin/product/prod_123/brand' \
|
||||
curl 'http://localhost:9000/admin/products/prod_123/brand' \
|
||||
-H 'Authorization: Bearer {token}'
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user