feat(core-flows,dashboard,medusa): fixes set of tiny bugs in claims flow (#8551)
* feat(types,dashboard): ability to set shipping methods for claim * chore: fix a bunch of stuff * chore: update comment
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { IOrderModuleService, UpdateOrderChangeDTO } from "@medusajs/types"
|
||||
import {
|
||||
ModuleRegistrationName,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updateOrderChangesStepId = "update-order-shopping-methods"
|
||||
/**
|
||||
* This step updates order change.
|
||||
*/
|
||||
export const updateOrderChangesStep = createStep(
|
||||
updateOrderChangesStepId,
|
||||
async (data: UpdateOrderChangeDTO[], { container }) => {
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||
objectFields: ["metadata"],
|
||||
})
|
||||
|
||||
const dataBeforeUpdate = await service.listOrderChanges(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
|
||||
const updated = await service.updateOrderChanges(data)
|
||||
|
||||
return new StepResponse(updated, dataBeforeUpdate)
|
||||
},
|
||||
async (dataBeforeUpdate, { container }) => {
|
||||
if (!dataBeforeUpdate?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
await service.updateOrderChanges(dataBeforeUpdate as UpdateOrderChangeDTO[])
|
||||
}
|
||||
)
|
||||
@@ -10,7 +10,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updateOrderShippingMethodsStepId = "update-order-shopping-methods"
|
||||
/**
|
||||
* This step updats order shipping methods.
|
||||
* This step updates order shipping methods.
|
||||
*/
|
||||
export const updateOrderShippingMethodsStep = createStep(
|
||||
updateOrderShippingMethodsStepId,
|
||||
|
||||
@@ -19,6 +19,7 @@ import { updateOrderClaimsStep } from "../../steps/claim/update-order-claims"
|
||||
import { createOrderChangeActionsStep } from "../../steps/create-order-change-actions"
|
||||
import { previewOrderChangeStep } from "../../steps/preview-order-change"
|
||||
import { createReturnsStep } from "../../steps/return/create-returns"
|
||||
import { updateOrderChangesStep } from "../../steps/update-order-changes"
|
||||
import {
|
||||
throwIfIsCancelled,
|
||||
throwIfItemsDoesNotExistsInOrder,
|
||||
@@ -121,6 +122,17 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
|
||||
name: "order-change-query",
|
||||
})
|
||||
|
||||
when({ createdReturn }, ({ createdReturn }) => {
|
||||
return !!createdReturn?.length
|
||||
}).then(() => {
|
||||
updateOrderChangesStep([
|
||||
{
|
||||
id: orderChange.id,
|
||||
return_id: createdReturn?.[0]?.id,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
orderClaimRequestItemReturnValidationStep({
|
||||
order,
|
||||
items: input.items,
|
||||
|
||||
@@ -84,11 +84,11 @@ function prepareFulfillmentData({
|
||||
order.items!.map((i) => [i.id, i])
|
||||
)
|
||||
const fulfillmentItems = items.map((i) => {
|
||||
const orderItem = orderItemsMap.get(i.item_id) ?? i.item
|
||||
const orderItem = orderItemsMap.get(i.id) ?? i.item
|
||||
|
||||
return {
|
||||
line_item_id: i.item_id,
|
||||
quantity: !isReturn ? i.quantity : undefined,
|
||||
return_quantity: isReturn ? i.quantity : undefined,
|
||||
quantity: i.quantity,
|
||||
title: orderItem.variant_title ?? orderItem.title,
|
||||
sku: orderItem.variant_sku || "",
|
||||
barcode: orderItem.variant_barcode || "",
|
||||
@@ -160,7 +160,7 @@ function extractShippingOption({ orderPreview, orderClaim, returnId }) {
|
||||
|
||||
for (const action of modifiedShippingMethod_.actions) {
|
||||
if (action.action === ChangeActionType.SHIPPING_ADD) {
|
||||
if (action.return_id === returnId) {
|
||||
if (action.return?.id === returnId) {
|
||||
returnShippingMethod = shippingMethod
|
||||
} else if (action.claim_id === orderClaim.id) {
|
||||
claimShippingMethod = shippingMethod
|
||||
@@ -181,7 +181,9 @@ export const confirmClaimRequestWorkflowId = "confirm-claim-request"
|
||||
*/
|
||||
export const confirmClaimRequestWorkflow = createWorkflow(
|
||||
confirmClaimRequestWorkflowId,
|
||||
function (input: ConfirmClaimRequestWorkflowInput): WorkflowResponse<OrderDTO> {
|
||||
function (
|
||||
input: ConfirmClaimRequestWorkflowInput
|
||||
): WorkflowResponse<OrderDTO> {
|
||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||
entry_point: "order_claim",
|
||||
fields: ["id", "status", "order_id", "canceled_at"],
|
||||
@@ -196,11 +198,8 @@ export const confirmClaimRequestWorkflow = createWorkflow(
|
||||
"id",
|
||||
"version",
|
||||
"canceled_at",
|
||||
"items.id",
|
||||
"items.title",
|
||||
"items.variant_title",
|
||||
"items.variant_sku",
|
||||
"items.variant_barcode",
|
||||
"items.*",
|
||||
"items.item.id",
|
||||
"shipping_address.*",
|
||||
],
|
||||
variables: { id: orderClaim.order_id },
|
||||
|
||||
Reference in New Issue
Block a user