Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Empty allItems array in order edit confirmation workflow causes inventory reservation failure #11950

Open
docloulou opened this issue Mar 23, 2025 · 0 comments

Comments

@docloulou
Copy link
Contributor

docloulou commented Mar 23, 2025

Package.json file

2.6.1

Node.js version

v20

Database and its version

16

Operating system name and version

linux

Browser name

chrome

What happended?

During the confirmOrderEditRequestWorkflow, there's an issue where the allItems array can end up empty even when there are valid order items that should be processed. This prevents proper inventory reservation for order edits and can lead to unexpected behavior.

Expected behavior

Actual behavior

When processing order edits via the confirmOrderEditRequestWorkflow, the transform function responsible for preparing inventory reservation data may result in empty allItems and allVariants arrays. This occurs specifically in the section that calculates newQuantity and applies filtering logic:

const newQuantity = updateAction
  ? MathBN.sub(quantity, ordItem.raw_quantity)
  : quantity

if (MathBN.lte(newQuantity, 0)) {
  return
}

const { variants, items } = transform(
{ orderItems, orderPreview },
({ orderItems, orderPreview }) => {
const allItems: any[] = []
const allVariants: any[] = []
orderItems.items.forEach((ordItem) => {
const itemAction = orderPreview.items?.find(
(item) =>
item.id === ordItem.id &&
item.actions?.find(
(a) =>
a.action === ChangeActionType.ITEM_ADD ||
a.action === ChangeActionType.ITEM_UPDATE
)
)
if (!itemAction) {
return
}
const unitPrice: BigNumberInput =
itemAction.raw_unit_price ?? itemAction.unit_price
const compareAtUnitPrice: BigNumberInput | undefined =
itemAction.raw_compare_at_unit_price ??
itemAction.compare_at_unit_price
const updateAction = itemAction.actions!.find(
(a) => a.action === ChangeActionType.ITEM_UPDATE
)
const quantity: BigNumberInput =
itemAction.raw_quantity ?? itemAction.quantity
const newQuantity = updateAction
? MathBN.sub(quantity, ordItem.raw_quantity)
: quantity
if (MathBN.lte(newQuantity, 0)) {
return
}
const reservationQuantity = MathBN.sub(
newQuantity,
ordItem.raw_fulfilled_quantity
)
allItems.push({
id: ordItem.id,
variant_id: ordItem.variant_id,
quantity: reservationQuantity,
unit_price: unitPrice,
compare_at_unit_price: compareAtUnitPrice,
})
allVariants.push(ordItem.variant)
})
return {
variants: allVariants,
items: allItems,
}
}
)

  1. When newQuantity evaluates to zero or negative, the item is skipped entirely.
  2. Quantity Decrease: Any edit that decreases quantity will result in negative newQuantity and be filtered out.
  3. Partially Fulfilled Orders: If an order is partially fulfilled and the remaining quantity is being modified, the calculation might not account for this correctly.
  4. Multiple Sequential Edits: If multiple edits are performed in sequence, calculations might compound incorrectly. (only the last added are accounted - previous change reservation are deleted by deleteReservationsByLineItemsStep but not in accounted because order.items[x].actions[x] is now empty)
  5. in case of ITEM_UPDATE the raw_quantity is already updated according to order.items[x].actions[x].details.quantity that lead to newQuantity = 0

Link to reproduction repo

na

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant