fix(core-flows): Allow adding shipping methods through order edits (#11504)
* fix(core-flows): Allow adding shipping methods through order edits * fix(core-flows): Allow adding shipping methods through order edits * update test description --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
215553792b
commit
efd66c0d59
5
.changeset/shaggy-ravens-wonder.md
Normal file
5
.changeset/shaggy-ravens-wonder.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(core-flows): Allow adding shipping methods through order edits
|
||||||
@@ -505,5 +505,78 @@ medusaIntegrationTestRunner({
|
|||||||
expect(result[0].confirmed_by).toEqual(expect.stringContaining("user_"))
|
expect(result[0].confirmed_by).toEqual(expect.stringContaining("user_"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("Order Edit Shipping Methods", () => {
|
||||||
|
it("should add a shipping method through an order edit", async () => {
|
||||||
|
await api.post(
|
||||||
|
"/admin/order-edits",
|
||||||
|
{ order_id: order.id, description: "Test" },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const orderId = order.id
|
||||||
|
|
||||||
|
const shippingMethodResponse = await api.post(
|
||||||
|
`/admin/order-edits/${orderId}/shipping-method`,
|
||||||
|
{ shipping_option_id: shippingOption.id, custom_amount: 5 },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
shippingMethodResponse.data.order_preview.shipping_methods.length
|
||||||
|
).toEqual(2)
|
||||||
|
expect(
|
||||||
|
shippingMethodResponse.data.order_preview.shipping_methods
|
||||||
|
).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 10,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
amount: 5,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
const requestResult = await api.post(
|
||||||
|
`/admin/order-edits/${orderId}/request`,
|
||||||
|
{},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(requestResult.data.order_preview.order_change.status).toEqual(
|
||||||
|
OrderChangeStatus.REQUESTED
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/order-edits/${orderId}/confirm`,
|
||||||
|
{},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const orderResult = await api.get(
|
||||||
|
`/admin/orders/${orderId}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(orderResult.data.order.shipping_methods.length).toEqual(2)
|
||||||
|
expect(orderResult.data.order.shipping_methods).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({ amount: 10 }),
|
||||||
|
expect.objectContaining({ amount: 5 }),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
const orderChangesResult = await api.get(
|
||||||
|
`/admin/orders/${orderId}/changes?change_type=edit`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(orderChangesResult.data.order_changes.length).toEqual(1)
|
||||||
|
expect(orderChangesResult.data.order_changes[0].status).toEqual(
|
||||||
|
OrderChangeStatus.CONFIRMED
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ export type CreateOrderEditShippingMethodValidationStepInput = {
|
|||||||
/**
|
/**
|
||||||
* This step validates that a shipping method can be created for an order edit.
|
* This step validates that a shipping method can be created for an order edit.
|
||||||
* If the order is canceled or the order change is not active, the step will throw an error.
|
* If the order is canceled or the order change is not active, the step will throw an error.
|
||||||
*
|
*
|
||||||
* :::note
|
* :::note
|
||||||
*
|
*
|
||||||
* You can retrieve an order and order change details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
|
* You can retrieve an order and order change details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
|
||||||
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
|
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
|
||||||
*
|
*
|
||||||
* :::
|
* :::
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const data = createOrderEditShippingMethodValidationStep({
|
* const data = createOrderEditShippingMethodValidationStep({
|
||||||
* order: {
|
* order: {
|
||||||
@@ -94,10 +94,10 @@ export const createOrderEditShippingMethodWorkflowId =
|
|||||||
/**
|
/**
|
||||||
* This workflow creates a shipping method for an order edit. It's used by the
|
* This workflow creates a shipping method for an order edit. It's used by the
|
||||||
* [Add Shipping Method API Route](https://docs.medusajs.com/api/admin#order-edits_postordereditsidshippingmethod).
|
* [Add Shipping Method API Route](https://docs.medusajs.com/api/admin#order-edits_postordereditsidshippingmethod).
|
||||||
*
|
*
|
||||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to create a shipping method
|
* You can use this workflow within your customizations or your own custom workflows, allowing you to create a shipping method
|
||||||
* for an order edit in your in your own custom flows.
|
* for an order edit in your in your own custom flows.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const { result } = await createOrderEditShippingMethodWorkflow(container)
|
* const { result } = await createOrderEditShippingMethodWorkflow(container)
|
||||||
* .run({
|
* .run({
|
||||||
@@ -106,14 +106,16 @@ export const createOrderEditShippingMethodWorkflowId =
|
|||||||
* shipping_option_id: "so_123",
|
* shipping_option_id: "so_123",
|
||||||
* }
|
* }
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
* @summary
|
* @summary
|
||||||
*
|
*
|
||||||
* Create a shipping method for an order edit.
|
* Create a shipping method for an order edit.
|
||||||
*/
|
*/
|
||||||
export const createOrderEditShippingMethodWorkflow = createWorkflow(
|
export const createOrderEditShippingMethodWorkflow = createWorkflow(
|
||||||
createOrderEditShippingMethodWorkflowId,
|
createOrderEditShippingMethodWorkflowId,
|
||||||
function (input: CreateOrderEditShippingMethodWorkflowInput): WorkflowResponse<OrderPreviewDTO> {
|
function (
|
||||||
|
input: CreateOrderEditShippingMethodWorkflowInput
|
||||||
|
): WorkflowResponse<OrderPreviewDTO> {
|
||||||
const order: OrderDTO = useRemoteQueryStep({
|
const order: OrderDTO = useRemoteQueryStep({
|
||||||
entry_point: "orders",
|
entry_point: "orders",
|
||||||
fields: ["id", "status", "currency_code", "canceled_at"],
|
fields: ["id", "status", "currency_code", "canceled_at"],
|
||||||
@@ -152,6 +154,7 @@ export const createOrderEditShippingMethodWorkflow = createWorkflow(
|
|||||||
|
|
||||||
const shippingMethodInput = transform(
|
const shippingMethodInput = transform(
|
||||||
{
|
{
|
||||||
|
relatedEntity: { order_id: order.id },
|
||||||
shippingOptions,
|
shippingOptions,
|
||||||
customPrice: input.custom_amount,
|
customPrice: input.custom_amount,
|
||||||
orderChange,
|
orderChange,
|
||||||
|
|||||||
Reference in New Issue
Block a user