Skip to content

Commit

Permalink
fix(core): Fix merging order with conflicting products using UseGuest…
Browse files Browse the repository at this point in the history
…Strategy (#3155)
  • Loading branch information
gkielwasser authored Nov 15, 2024
1 parent 71f85d2 commit f0607aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
19 changes: 19 additions & 0 deletions packages/core/e2e/order-merge.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ describe('Order merging', () => {
).toEqual([{ productVariantId: 'T_5', quantity: 3 }]);
});

it('UseGuestStrategy with conflicting lines', async () => {
const result = await testMerge({
strategy: new UseGuestStrategy(),
customerEmailAddress: customers[8].emailAddress,
existingOrderLines: [
{ productVariantId: 'T_7', quantity: 1 },
{ productVariantId: 'T_8', quantity: 1 },
],
guestOrderLines: [{ productVariantId: 'T_8', quantity: 3 }],
});

expect(
(result?.lines || []).sort(sortById).map(line => ({
productVariantId: line.productVariant.id,
quantity: line.quantity,
})),
).toEqual([{ productVariantId: 'T_8', quantity: 3 }]);
});

it('UseGuestIfExistingEmptyStrategy with empty existing', async () => {
const result = await testMerge({
strategy: new UseGuestIfExistingEmptyStrategy(),
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,15 @@ export class OrderService {
if (orderToDelete) {
await this.deleteOrder(ctx, orderToDelete);
}
if (order && linesToDelete) {
const orderId = order.id;
for (const line of linesToDelete) {
const result = await this.removeItemFromOrder(ctx, orderId, line.orderLineId);
if (!isGraphQlErrorResult(result)) {
order = result;
}
}
}
if (order && linesToInsert) {
const orderId = order.id;
for (const line of linesToInsert) {
Expand Down Expand Up @@ -1649,15 +1658,6 @@ export class OrderService {
}
}
}
if (order && linesToDelete) {
const orderId = order.id;
for (const line of linesToDelete) {
const result = await this.removeItemFromOrder(ctx, orderId, line.orderLineId);
if (!isGraphQlErrorResult(result)) {
order = result;
}
}
}
const customer = await this.customerService.findOneByUserId(ctx, user.id);
if (order && customer) {
order.customer = customer;
Expand Down

0 comments on commit f0607aa

Please sign in to comment.