Răsfoiți Sursa

fix(core): Fix coupon code removal not clearing adjustments

The removeCouponCode() method was capturing OrderLine references before
calling applyPriceAdjustments(), then saving those stale references
afterward, which overwrote the correctly cleared adjustments.

Since applyPriceAdjustments() already saves OrderLines with the correct
(cleared) adjustments, the separate save was both redundant and buggy.

Fixes #4016
Jan Tokic 2 zile în urmă
părinte
comite
bf397cccfb
1 a modificat fișierele cu 1 adăugiri și 12 ștergeri
  1. 1 12
      packages/core/src/service/services/order.service.ts

+ 1 - 12
packages/core/src/service/services/order.service.ts

@@ -12,7 +12,6 @@ import {
     AddFulfillmentToOrderResult,
     AddManualPaymentToOrderResult,
     AddNoteToOrderInput,
-    AdjustmentType,
     CancelOrderInput,
     CancelOrderResult,
     CancelPaymentResult,
@@ -1028,14 +1027,6 @@ export class OrderService {
     async removeCouponCode(ctx: RequestContext, orderId: ID, couponCode: string) {
         const order = await this.getOrderOrThrow(ctx, orderId);
         if (order.couponCodes.includes(couponCode)) {
-            // When removing a couponCode which has triggered an Order-level discount
-            // we need to make sure we persist the changes to the adjustments array of
-            // any affected OrderLines.
-            const affectedOrderLines = order.lines.filter(
-                line =>
-                    line.adjustments.filter(a => a.type === AdjustmentType.DISTRIBUTED_ORDER_PROMOTION)
-                        .length,
-            );
             order.couponCodes = order.couponCodes.filter(cc => cc !== couponCode);
             await this.historyService.createHistoryEntryForOrder({
                 ctx,
@@ -1044,9 +1035,7 @@ export class OrderService {
                 data: { couponCode },
             });
             await this.eventBus.publish(new CouponCodeEvent(ctx, couponCode, orderId, 'removed'));
-            const result = await this.applyPriceAdjustments(ctx, order);
-            await this.connection.getRepository(ctx, OrderLine).save(affectedOrderLines);
-            return result;
+            return this.applyPriceAdjustments(ctx, order);
         } else {
             return order;
         }