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(core): Fix merging order with conflicting products #3155

Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading