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

fix(medusa): Order edit confirmation conflict line items update #5867

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-flowers-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Order edit confirmation conflict line items update
30 changes: 18 additions & 12 deletions packages/medusa/src/services/order-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,32 +753,38 @@ export default class OrderEditService extends TransactionBaseService {

const lineItemServiceTx = this.lineItemService_.withTransaction(manager)

const [lineItems] = await promiseAll([
lineItemServiceTx.update(
{ order_id: orderEdit.order_id },
{ order_id: null }
),
// Detach the original order line items from the order
const originalOrderLineItems = await lineItemServiceTx.update(
{ order_id: orderEdit.order_id },
{ order_id: null }
)

const promises: Promise<any>[] = []

// Attach the order edit item to the order
promises.push(
lineItemServiceTx.update(
{ order_edit_id: orderEditId },
{ order_id: orderEdit.order_id }
),
])
)
)

orderEdit.confirmed_at = new Date()
orderEdit.confirmed_by = context.confirmedBy

orderEdit = await orderEditRepository.save(orderEdit)

if (this.inventoryService_) {
const itemsIds = lineItems.map((i) => i.id)
await this.inventoryService_!.deleteReservationItemsByLineItem(
itemsIds,
{
const itemsIds = originalOrderLineItems.map((i) => i.id)
promises.push(
this.inventoryService_!.deleteReservationItemsByLineItem(itemsIds, {
transactionManager: manager,
}
})
)
}

await promiseAll(promises)

await this.eventBusService_
.withTransaction(manager)
.emit(OrderEditService.Events.CONFIRMED, { id: orderEditId })
Expand Down