feat(core-flows): order add quantity diff (#10065)
This commit is contained in:
committed by
GitHub
parent
ffa3a15ba1
commit
fc5d2b5fca
5
.changeset/honest-chefs-attend.md
Normal file
5
.changeset/honest-chefs-attend.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/core-flows": patch
|
||||
---
|
||||
|
||||
Order edit quantity diff
|
||||
@@ -1,10 +1,10 @@
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
OrderChangeStatus,
|
||||
RuleOperator,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
@@ -418,6 +418,31 @@ medusaIntegrationTestRunner({
|
||||
expect(result.summary.current_order_total).toEqual(124)
|
||||
expect(result.summary.original_order_total).toEqual(60)
|
||||
|
||||
const updatedItem = result.items.find((i) => i.id === item.id)
|
||||
expect(updatedItem.actions).toEqual([
|
||||
expect.objectContaining({
|
||||
details: expect.objectContaining({
|
||||
quantity: 2,
|
||||
unit_price: 25,
|
||||
quantity_diff: 0,
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
details: expect.objectContaining({
|
||||
quantity: 3,
|
||||
unit_price: 25,
|
||||
quantity_diff: 1,
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
details: expect.objectContaining({
|
||||
quantity: 3,
|
||||
unit_price: 30,
|
||||
quantity_diff: 1,
|
||||
}),
|
||||
}),
|
||||
])
|
||||
|
||||
// Remove the item by setting the quantity to 0
|
||||
result = (
|
||||
await api.post(
|
||||
|
||||
@@ -4,7 +4,12 @@ import {
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/framework/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/framework/utils"
|
||||
import {
|
||||
BigNumber,
|
||||
ChangeActionType,
|
||||
MathBN,
|
||||
OrderChangeStatus,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
@@ -75,19 +80,30 @@ export const orderEditUpdateItemQuantityWorkflow = createWorkflow(
|
||||
const orderChangeActionInput = transform(
|
||||
{ order, orderChange, items: input.items },
|
||||
({ order, orderChange, items }) => {
|
||||
return items.map((item) => ({
|
||||
order_change_id: orderChange.id,
|
||||
order_id: order.id,
|
||||
version: orderChange.version,
|
||||
action: ChangeActionType.ITEM_UPDATE,
|
||||
internal_note: item.internal_note,
|
||||
details: {
|
||||
reference_id: item.id,
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
compare_at_unit_price: item.compare_at_unit_price,
|
||||
},
|
||||
}))
|
||||
return items.map((item) => {
|
||||
const existing = order?.items?.find(
|
||||
(exItem) => exItem.id === item.id
|
||||
)!
|
||||
|
||||
const quantityDiff = new BigNumber(
|
||||
MathBN.sub(item.quantity, existing.quantity)
|
||||
)
|
||||
|
||||
return {
|
||||
order_change_id: orderChange.id,
|
||||
order_id: order.id,
|
||||
version: orderChange.version,
|
||||
action: ChangeActionType.ITEM_UPDATE,
|
||||
internal_note: item.internal_note,
|
||||
details: {
|
||||
reference_id: item.id,
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
compare_at_unit_price: item.compare_at_unit_price,
|
||||
quantity_diff: quantityDiff,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user