|
1
|
import { StepResponse } from "@medusajs/framework/workflows-sdk" |
|
2
|
import { completeCartWorkflow } from "@medusajs/medusa/core-flows" |
|
3
|
import { cloneCartGiftCardsToOrderWorkflow } from "../orders/workflows/link-gift-cards-to-order" |
|
4
|
;(completeCartWorkflow.hooks as any).orderCreated( |
|
5
|
async (data: { order_id: string; cart_id: string }, stepContext) => { |
|
6
|
const { container, ...sharedContext } = stepContext |
|
7
|
const { order_id, cart_id } = data |
|
8
|
|
|
9
|
const transaction = await cloneCartGiftCardsToOrderWorkflow.run({ |
|
10
|
input: { |
|
11
|
order_id: order_id, |
|
12
|
cart_id: cart_id, |
|
13
|
}, |
|
14
|
container, |
|
15
|
context: { ...sharedContext, preventReleaseEvents: true }, |
|
16
|
}) |
|
17
|
|
|
18
|
const { result } = transaction |
|
19
|
|
|
20
|
return new StepResponse(result, stepContext.transactionId) |
|
21
|
}, |
|
22
|
async (transactionId, stepContext) => { |
|
23
|
if (!transactionId) { |
|
24
|
return |
|
25
|
} |
|
26
|
|
|
27
|
const { container, ...sharedContext } = stepContext |
|
28
|
|
|
29
|
await cloneCartGiftCardsToOrderWorkflow(container).cancel({ |
|
30
|
transactionId, |
|
31
|
container, |
|
32
|
context: { ...sharedContext }, |
|
33
|
}) |
|
34
|
} |
|
35
|
) |