Commit eaf9a7c9 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Issue #3256456 by jsacksick: Promotion usage is incorrectly registered.

parent 799c8973
Loading
Loading
Loading
Loading
+10 −5
Changes for modules/promotion/src/EventSubscriber/OrderEventSubscriber.php: 10 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ class OrderEventSubscriber implements EventSubscriberInterface {
      $coupon_promotion_ids[] = $coupon->getPromotionId();
    }

    $promotion_ids = [];
    $adjustments = $order->collectAdjustments();
    foreach ($adjustments as $adjustment) {
      if ($adjustment->getType() != 'promotion') {
@@ -78,12 +79,16 @@ class OrderEventSubscriber implements EventSubscriberInterface {

      $promotion_id = $adjustment->getSourceId();
      if ($promotion_id && !in_array($promotion_id, $coupon_promotion_ids)) {
        $promotion = $this->promotionStorage->load($promotion_id);
        // Not every adjustment can be mapped to a promotion (because the
        // the promotion was deleted, or because the adjustment is custom).
        if ($promotion) {
          $this->usage->register($order, $promotion);
        $promotion_ids[$promotion_id] = $promotion_id;
      }
    }

    if ($promotion_ids) {
      $promotions = $this->promotionStorage->loadMultiple($promotion_ids);

      /** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */
      foreach ($promotions as $promotion) {
        $this->usage->register($order, $promotion);
      }
    }
  }