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