feat: Returns order previews (#8135)
* work on order previews * fix create return shipping flow * fix http tests * fix tests
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { previewOrderChangeStep } from "../steps"
|
||||
import { confirmOrderChanges } from "../steps/confirm-order-changes"
|
||||
import { createReturnItems } from "../steps/create-return-items"
|
||||
import {
|
||||
@@ -38,7 +39,7 @@ const validationStep = createStep(
|
||||
export const confirmReturnRequestWorkflowId = "confirm-return-request"
|
||||
export const confirmReturnRequestWorkflow = createWorkflow(
|
||||
confirmReturnRequestWorkflowId,
|
||||
function (input: WorkflowInput): WorkflowData<void> {
|
||||
function (input: WorkflowInput): WorkflowData<OrderDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id"],
|
||||
@@ -86,5 +87,7 @@ export const confirmReturnRequestWorkflow = createWorkflow(
|
||||
createReturnItems({ returnId: orderReturn.id, changes: returnItemActions })
|
||||
|
||||
confirmOrderChanges({ changes: [orderChange], orderId: order.id })
|
||||
|
||||
return previewOrderChangeStep(order.id)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { previewOrderChangeStep } from "../steps"
|
||||
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
||||
import { createOrderShippingMethods } from "../steps/create-order-shipping-methods"
|
||||
import { previewOrderChangeStep } from "../steps/preview-order-change"
|
||||
import {
|
||||
throwIfIsCancelled,
|
||||
throwIfOrderChangeIsNotActive,
|
||||
@@ -45,7 +45,7 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
||||
return_id: string
|
||||
shipping_option_id: string
|
||||
custom_price?: BigNumberInput
|
||||
}): WorkflowData {
|
||||
}): WorkflowData<OrderDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id"],
|
||||
@@ -93,14 +93,19 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
||||
validationStep({ order, orderReturn, orderChange })
|
||||
|
||||
const shippingMethodInput = transform(
|
||||
{ orderReturn, shippingOptions, orderChange },
|
||||
{
|
||||
orderReturn,
|
||||
shippingOptions,
|
||||
customPrice: input.custom_price,
|
||||
orderChange,
|
||||
},
|
||||
(data) => {
|
||||
const option = data.shippingOptions[0]
|
||||
const orderChange = data.orderChange
|
||||
|
||||
return {
|
||||
shipping_option_id: option.id,
|
||||
amount: option.calculated_price.calculated_amount,
|
||||
amount: data.customPrice ?? option.calculated_price.calculated_amount,
|
||||
is_tax_inclusive:
|
||||
!!option.calculated_price.is_calculated_price_tax_inclusive,
|
||||
data: option.data ?? {},
|
||||
@@ -141,8 +146,8 @@ export const createReturnShippingMethodWorkflow = createWorkflow(
|
||||
return {
|
||||
action: ChangeActionType.SHIPPING_ADD,
|
||||
reference: "order_shipping_method",
|
||||
reference_id: createdMethod.id,
|
||||
order_change_id: orderChange.id,
|
||||
reference_id: createdMethod.id,
|
||||
amount: methodPrice,
|
||||
order_id: order.id,
|
||||
return_id: orderReturn.id,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderWorkflow,
|
||||
@@ -13,6 +12,7 @@ import {
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { previewOrderChangeStep } from "../steps"
|
||||
import { createOrderChangeActionsStep } from "../steps/create-order-change-actions"
|
||||
import {
|
||||
throwIfIsCancelled,
|
||||
@@ -45,7 +45,7 @@ export const requestItemReturnWorkflow = createWorkflow(
|
||||
requestItemReturnWorkflowId,
|
||||
function (
|
||||
input: WorkflowData<OrderWorkflow.RequestItemReturnWorkflowInput>
|
||||
): WorkflowData<OrderChangeActionDTO[]> {
|
||||
): WorkflowData<OrderDTO> {
|
||||
const orderReturn: ReturnDTO = useRemoteQueryStep({
|
||||
entry_point: "return",
|
||||
fields: ["id", "status", "order_id"],
|
||||
@@ -94,6 +94,8 @@ export const requestItemReturnWorkflow = createWorkflow(
|
||||
}
|
||||
)
|
||||
|
||||
return createOrderChangeActionsStep(orderChangeActionInput)
|
||||
createOrderChangeActionsStep(orderChangeActionInput)
|
||||
|
||||
return previewOrderChangeStep(order.id)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user