Skip to content

Commit

Permalink
fix(core): Correctly remove invalid promotion couponCodes from Order
Browse files Browse the repository at this point in the history
Using the `removeCouponCode` method will create an order history entry, making it easier to track
and debug an order.
  • Loading branch information
michaelbromley committed Mar 16, 2023
1 parent ad7eab8 commit 7a1c127
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/core/src/service/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,24 +1422,20 @@ export class OrderService {
await this.connection.getRepository(ctx, Order).save(order, { reload: false });
// Check that any applied couponCodes are still valid now that
// we know the Customer.
let updatedOrder = order;
if (order.couponCodes) {
let codesRemoved = false;
for (const couponCode of order.couponCodes.slice()) {
const validationResult = await this.promotionService.validateCouponCode(
ctx,
couponCode,
customer.id,
);
if (isGraphQlErrorResult(validationResult)) {
order.couponCodes = order.couponCodes.filter(c => c !== couponCode);
codesRemoved = true;
updatedOrder = await this.removeCouponCode(ctx, orderId, couponCode);
}
}
if (codesRemoved) {
return this.applyPriceAdjustments(ctx, order);
}
}
return order;
return updatedOrder;
}

/**
Expand Down

0 comments on commit 7a1c127

Please sign in to comment.