From cc829185f4c44999b7dc469d78ccb6c4a4ddf6df Mon Sep 17 00:00:00 2001 From: Avia-Code Date: Tue, 4 Mar 2025 12:53:39 +0200 Subject: [PATCH] feat: added hook for createStockLocationsWorkflow (#11491) What This commit introduces the `stockLocationsCreated` hook to the `createStockLocationsWorkflow`. Why The hook was missing and necessary to improve the workflow's extensibility. How Added the `stockLocationsCreated` hook and updated related logic within the workflow. Testing 1. Create new medusa project via create-medusa-app 2. Connect this custom branch of medusa to it 3. Create `src/workflows/hooks/stock-locations-created.ts` file with the following content: ``` import { createStockLocationsWorkflow } from "@medusajs/medusa/core-flows" createStockLocationsWorkflow.hooks.stockLocationsCreated( (async ({ stockLocations, additional_data }, { container }) => { console.log({stockLocations}) }) ) ``` 4. Create new admin account and create there a new stock location 5. The log should be displayed in terminal --- .../workflows/create-stock-locations.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/core-flows/src/stock-location/workflows/create-stock-locations.ts b/packages/core/core-flows/src/stock-location/workflows/create-stock-locations.ts index 2794fe2f0b..8ddd079868 100644 --- a/packages/core/core-flows/src/stock-location/workflows/create-stock-locations.ts +++ b/packages/core/core-flows/src/stock-location/workflows/create-stock-locations.ts @@ -1,6 +1,7 @@ import { WorkflowData, WorkflowResponse, + createHook, createWorkflow, } from "@medusajs/framework/workflows-sdk" @@ -44,6 +45,14 @@ export const createStockLocationsWorkflowId = "create-stock-locations-workflow" export const createStockLocationsWorkflow = createWorkflow( createStockLocationsWorkflowId, (input: WorkflowData) => { - return new WorkflowResponse(createStockLocations(input.locations)) + const stockLocations = createStockLocations(input.locations) + + const stockLocationsCreated = createHook("stockLocationsCreated", { + stockLocations, + }) + + return new WorkflowResponse(stockLocations, { + hooks: [stockLocationsCreated], + }) } )