diff --git a/modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php b/modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php index a1f50bc8..e410bc8d 100644 --- a/modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php +++ b/modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php @@ -457,6 +457,13 @@ class BuyXGetY extends OrderPromotionOfferBase { /** @var \Drupal\commerce_order\Entity\OrderInterface $order */ $order = $entity; + // Clear out any locked promotion adjustment added by this offer plugin. + foreach ($order->getItems() as $order_item) { + $order_item->setAdjustments(array_filter($order_item->getAdjustments(), function (Adjustment $adjustment) use ($promotion) { + return $adjustment->getSourceId() !== $promotion->id(); + })); + } + // Check if we have any order item whose quantity has been changed by this // promotion, and subtract that amount. If the promotion still applies, the // necessary quantity will be added back in ::apply(). Order items that will @@ -467,9 +474,6 @@ class BuyXGetY extends OrderPromotionOfferBase { return $order_item->getData("promotion:{$promotion->id()}:auto_add_quantity"); }); foreach ($auto_add_order_items as $order_item) { - $order_item->setAdjustments(array_filter($order_item->getAdjustments(), function (Adjustment $adjustment) use ($promotion) { - return $adjustment->getSourceId() !== $promotion->id(); - })); $new_quantity = Calculator::subtract($order_item->getQuantity(), $order_item->getData("promotion:{$promotion->id()}:auto_add_quantity")); $order_item->setQuantity($new_quantity); }