protected int applyLegacyAdjustments(
     int appliedItemOffersCount,
     PromotableCandidateItemOffer itemOffer,
     int beforeCount,
     PromotableOrderItem orderItem) {
   // legacy promotion
   if (!orderItem.isNotCombinableOfferApplied()) {
     if ((itemOffer.getOffer().isCombinableWithOtherOffers() && itemOffer.getOffer().isStackable())
         || !orderItem.isHasOrderItemAdjustments()) {
       applyOrderItemAdjustment(itemOffer, orderItem);
       appliedItemOffersCount++;
     }
   }
   // check if not combinable offer is better than sale price; if no, remove the not combinable
   // offer so
   // that another offer may be applied to the item
   if (!itemOffer.getOffer().isCombinableWithOtherOffers()
       && appliedItemOffersCount > beforeCount) {
     Money adjustmentTotal = new Money(0D);
     Money saleTotal = new Money(0D);
     adjustmentTotal =
         adjustmentTotal.add(orderItem.getCurrentPrice().multiply(orderItem.getQuantity()));
     saleTotal =
         saleTotal.add(
             orderItem.getPriceBeforeAdjustments(true).multiply(orderItem.getQuantity()));
     if (adjustmentTotal.greaterThanOrEqual(saleTotal)) {
       // adjustment price is not best price, remove adjustments for this item
       orderItem.removeAllAdjustments();
       appliedItemOffersCount--;
     }
   }
   return appliedItemOffersCount;
 }
  protected int checkLegacyAdjustments(
      List<PromotableOrderItem> discreteOrderItems, int appliedItemOffersCount) {
    if (appliedItemOffersCount > 0) {
      for (PromotableOrderItem discreteOrderItem : discreteOrderItems) {
        if (discreteOrderItem.isHasOrderItemAdjustments()) {
          boolean useSaleAdjustments = false;
          int adjustmentsRemoved = 0;

          Money adjustmentPrice;
          if (discreteOrderItem.getDelegate().getIsOnSale()) {
            if (discreteOrderItem
                .getSaleAdjustmentPrice()
                .lessThanOrEqual(discreteOrderItem.getRetailAdjustmentPrice())) {
              adjustmentPrice = discreteOrderItem.getSaleAdjustmentPrice();
              useSaleAdjustments = true;
            } else {
              adjustmentPrice = discreteOrderItem.getRetailAdjustmentPrice();
            }

            if (!adjustmentPrice.lessThanOrEqual(discreteOrderItem.getSalePrice())) {
              adjustmentsRemoved = adjustmentsRemoved + discreteOrderItem.removeAllAdjustments();
            }
          } else {
            if (!discreteOrderItem
                .getRetailAdjustmentPrice()
                .lessThanOrEqual(discreteOrderItem.getRetailPrice())) {
              adjustmentsRemoved = adjustmentsRemoved + discreteOrderItem.removeAllAdjustments();
            }
          }

          adjustmentsRemoved =
              adjustmentsRemoved + discreteOrderItem.fixAdjustments(useSaleAdjustments);
          appliedItemOffersCount -= adjustmentsRemoved;
        }
      }
    }
    return appliedItemOffersCount;
  }
  protected int checkAdjustments(PromotableOrder order, int appliedItemOffersCount) {
    if (appliedItemOffersCount > 0) {
      List<PromotableOrderItem> allSplitItems = order.getAllSplitItems();
      // compare adjustment price to sales price and remove adjustments if sales price is better
      for (PromotableOrderItem splitItem : allSplitItems) {
        if (splitItem.isHasOrderItemAdjustments()) {
          boolean useSaleAdjustments = false;
          int adjustmentsRemoved = 0;

          Money adjustmentPrice;
          if (splitItem.getDelegate().getIsOnSale()) {
            if (splitItem
                .getSaleAdjustmentPrice()
                .lessThanOrEqual(splitItem.getRetailAdjustmentPrice())) {
              adjustmentPrice = splitItem.getSaleAdjustmentPrice();
              useSaleAdjustments = true;
            } else {
              adjustmentPrice = splitItem.getRetailAdjustmentPrice();
            }

            if (!adjustmentPrice.lessThan(splitItem.getSalePrice())) {
              adjustmentsRemoved = adjustmentsRemoved + splitItem.removeAllAdjustments();
            }
          } else {
            if (!splitItem.getRetailAdjustmentPrice().lessThan(splitItem.getRetailPrice())) {
              adjustmentsRemoved = adjustmentsRemoved + splitItem.removeAllAdjustments();
            }
          }

          adjustmentsRemoved = adjustmentsRemoved + splitItem.fixAdjustments(useSaleAdjustments);
          appliedItemOffersCount -= adjustmentsRemoved;
        }
      }
      mergeSplitItems(order);
    }
    return appliedItemOffersCount;
  }