From 30171f3dc47d30a02a55807a430a276aaffc0cf3 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 19 Feb 2025 09:05:52 +0100 Subject: [PATCH] fix(core-flows): add no_notification to fulfillment created event (#11507) what: - passes no notification toggle to events - fulfillment created and canceled fixes https://github.com/medusajs/medusa/issues/11505 --- .../workflows/cancel-order-fulfillment.ts | 41 +++++++++---------- .../src/order/workflows/create-fulfillment.ts | 1 + 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts index e9671a3fba..b2f9ad34e8 100644 --- a/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/cancel-order-fulfillment.ts @@ -38,7 +38,7 @@ export type CancelOrderFulfillmentValidateOrderStep = { order: OrderDTO & { /** * The order's fulfillments. - */ + */ fulfillments: FulfillmentDTO[] } /** @@ -48,16 +48,16 @@ export type CancelOrderFulfillmentValidateOrderStep = { } /** - * This step validates that an order fulfillment can be canceled. If + * This step validates that an order fulfillment can be canceled. If * the fulfillment doesn't exist, or it has already been shipped, the step throws an error. - * + * * :::note - * + * * You can retrieve an order and fulfillment details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query), * or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep). - * + * * ::: - * + * * @example * const data = cancelOrderFulfillmentValidateOrder({ * order: { @@ -78,10 +78,7 @@ export type CancelOrderFulfillmentValidateOrderStep = { */ export const cancelOrderFulfillmentValidateOrder = createStep( "cancel-fulfillment-validate-order", - ({ - order, - input, - }: CancelOrderFulfillmentValidateOrderStep) => { + ({ order, input }: CancelOrderFulfillmentValidateOrderStep) => { throwIfOrderIsCancelled({ order }) const fulfillment = order.fulfillments.find( @@ -162,17 +159,18 @@ function prepareInventoryUpdate({ /** * The data to cancel an order's fulfillment, along with custom data that's passed to the workflow's hooks. */ -export type CancelOrderFulfillmentWorkflowInput = OrderWorkflow.CancelOrderFulfillmentWorkflowInput & AdditionalData +export type CancelOrderFulfillmentWorkflowInput = + OrderWorkflow.CancelOrderFulfillmentWorkflowInput & AdditionalData export const cancelOrderFulfillmentWorkflowId = "cancel-order-fulfillment" /** * This workflow cancels an order's fulfillment. It's used by the [Cancel Order's Fulfillment Admin API Route](https://docs.medusajs.com/api/admin#orders_postordersidfulfillmentsfulfillment_idcancel). - * - * This workflow has a hook that allows you to perform custom actions on the canceled fulfillment. For example, you can pass under `additional_data` custom data that + * + * This workflow has a hook that allows you to perform custom actions on the canceled fulfillment. For example, you can pass under `additional_data` custom data that * allows you to update custom data models linked to the fulfillment. - * + * * You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around canceling a fulfillment. - * + * * @example * const { result } = await cancelOrderFulfillmentWorkflow(container) * .run({ @@ -184,18 +182,16 @@ export const cancelOrderFulfillmentWorkflowId = "cancel-order-fulfillment" * } * } * }) - * + * * @summary - * + * * Cancel an order's fulfillment. - * + * * @property hooks.orderFulfillmentCanceled - This hook is executed after the fulfillment is canceled. You can consume this hook to perform custom actions on the canceled fulfillment. */ export const cancelOrderFulfillmentWorkflow = createWorkflow( cancelOrderFulfillmentWorkflowId, - ( - input: WorkflowData - ) => { + (input: WorkflowData) => { const order: OrderDTO & { fulfillments: FulfillmentDTO[] } = useRemoteQueryStep({ entry_point: "orders", @@ -227,10 +223,11 @@ export const cancelOrderFulfillmentWorkflow = createWorkflow( prepareInventoryUpdate ) - const eventData = transform({ order, fulfillment }, (data) => { + const eventData = transform({ order, fulfillment, input }, (data) => { return { order_id: data.order.id, fulfillment_id: data.fulfillment.id, + no_notification: data.input.no_notification, } }) diff --git a/packages/core/core-flows/src/order/workflows/create-fulfillment.ts b/packages/core/core-flows/src/order/workflows/create-fulfillment.ts index 05393a0e41..17af74f648 100644 --- a/packages/core/core-flows/src/order/workflows/create-fulfillment.ts +++ b/packages/core/core-flows/src/order/workflows/create-fulfillment.ts @@ -467,6 +467,7 @@ export const createOrderFulfillmentWorkflow = createWorkflow( data: { order_id: input.order_id, fulfillment_id: fulfillment.id, + no_notification: input.no_notification, }, }) )