feat: Fix subscribers loading + add order <> cart link (#7617)

This commit is contained in:
Oli Juhl
2024-06-09 12:31:28 +02:00
committed by GitHub
parent fbb00f3863
commit 3f661c917b
10 changed files with 99 additions and 76 deletions
@@ -1,12 +1,12 @@
import { OrderDTO } from "@medusajs/types"
import { Modules } from "@medusajs/utils"
import {
WorkflowData,
createWorkflow,
parallelize,
transform,
} from "@medusajs/workflows-sdk"
import { useRemoteQueryStep } from "../../../common"
import { linkOrderAndPaymentCollectionsStep } from "../../../order/steps"
import { createRemoteLinkStep, useRemoteQueryStep } from "../../../common"
import { authorizePaymentSessionStep } from "../../../payment/steps/authorize-payment-session"
import { createOrderFromCartStep, validateCartPaymentsStep } from "../steps"
import { reserveInventoryStep } from "../steps/reserve-inventory"
@@ -75,16 +75,18 @@ export const completeCartWorkflow = createWorkflow(
const order = createOrderFromCartStep({ cart: finalCart })
const linkOrderPaymentCollection = transform({ order, cart }, (data) => ({
links: [
{
order_id: data.order.id,
payment_collection_id: data.cart.payment_collection.id,
createRemoteLinkStep([
{
[Modules.ORDER]: { order_id: order.id },
[Modules.CART]: { cart_id: finalCart.id },
},
{
[Modules.ORDER]: { order_id: order.id },
[Modules.PAYMENT]: {
payment_collection_id: cart.payment_collection.id,
},
],
}))
linkOrderAndPaymentCollectionsStep(linkOrderPaymentCollection)
},
])
return order
}
@@ -3,7 +3,6 @@ export * from "./cancel-orders"
export * from "./complete-orders"
export * from "./create-orders"
export * from "./get-item-tax-lines"
export * from "./link-order-payment-collection"
export * from "./register-fulfillment"
export * from "./register-shipment"
export * from "./set-tax-lines-for-items"
@@ -1,42 +0,0 @@
import { Modules } from "@medusajs/modules-sdk"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type StepInput = {
links: {
order_id: string
payment_collection_id: string
}[]
}
export const linkOrderAndPaymentCollectionsStepId =
"link-order-payment-collection"
export const linkOrderAndPaymentCollectionsStep = createStep(
linkOrderAndPaymentCollectionsStepId,
async (data: StepInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const links = data.links.map((d) => ({
[Modules.ORDER]: { order_id: d.order_id },
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
}))
await remoteLink.create(links)
return new StepResponse(void 0, data)
},
async (data, { container }) => {
if (!data) {
return
}
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const links = data.links.map((d) => ({
[Modules.ORDER]: { order_id: d.order_id },
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
}))
await remoteLink.dismiss(links)
}
)