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; }
protected int applyAdjustments( PromotableOrder order, int appliedItemOffersCount, PromotableCandidateItemOffer itemOffer, int beforeCount) { boolean notCombinableOfferApplied = false; boolean offerApplied = false; List<PromotableOrderItem> allSplitItems = order.getAllSplitItems(); for (PromotableOrderItem targetItem : allSplitItems) { notCombinableOfferApplied = targetItem.isNotCombinableOfferApplied(); if (!offerApplied) { offerApplied = targetItem.isHasOrderItemAdjustments(); } if (notCombinableOfferApplied) { break; } } if (!notCombinableOfferApplied && (((itemOffer.getOffer().isCombinableWithOtherOffers() || itemOffer.getOffer().isTotalitarianOffer() == null || !itemOffer.getOffer().isTotalitarianOffer()) // && itemOffer.getOffer().isStackable() ) || !offerApplied)) { // At this point, we should not have any official adjustment on the order // for this item. applyItemQualifiersAndTargets(itemOffer, order); allSplitItems = order.getAllSplitItems(); for (PromotableOrderItem splitItem : allSplitItems) { for (PromotionDiscount discount : splitItem.getPromotionDiscounts()) { if (discount.getPromotion().equals(itemOffer.getOffer())) { applyOrderItemAdjustment(itemOffer, splitItem); appliedItemOffersCount++; break; } } } } // 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() || (itemOffer.getOffer().isTotalitarianOffer() != null && itemOffer.getOffer().isTotalitarianOffer())) && appliedItemOffersCount > beforeCount) { Money adjustmentTotal = new Money(0D); Money saleTotal = new Money(0D); for (PromotableOrderItem splitItem : allSplitItems) { adjustmentTotal = adjustmentTotal.add(splitItem.getCurrentPrice().multiply(splitItem.getQuantity())); saleTotal = saleTotal.add( splitItem.getPriceBeforeAdjustments(true).multiply(splitItem.getQuantity())); } if (adjustmentTotal.greaterThanOrEqual(saleTotal)) { // adjustment price is not best price, remove adjustments for this item for (PromotableOrderItem splitItem : allSplitItems) { if (splitItem.isHasOrderItemAdjustments()) { appliedItemOffersCount--; } } order.getSplitItems().clear(); } } return appliedItemOffersCount; }