use of org.broadleafcommerce.core.offer.domain.OfferTier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOfferUtility method determineOfferUnitValue.
@SuppressWarnings("unchecked")
public static BigDecimal determineOfferUnitValue(Offer offer, PromotableCandidateItemOffer promotableCandidateItemOffer) {
if (offer instanceof AdvancedOffer) {
AdvancedOffer advancedOffer = (AdvancedOffer) offer;
if (advancedOffer.isTieredOffer()) {
int quantity = promotableCandidateItemOffer.calculateTargetQuantityForTieredOffer();
List<OfferTier> offerTiers = advancedOffer.getOfferTiers();
Collections.sort(offerTiers, new BeanComparator("minQuantity"));
OfferTier maxTier = null;
// assuming that promotableOffer.getOffer()).getOfferTiers() is sorted already
for (OfferTier currentTier : offerTiers) {
if (quantity >= currentTier.getMinQuantity()) {
maxTier = currentTier;
} else {
break;
}
}
if (maxTier != null) {
return maxTier.getAmount();
}
if (OfferDiscountType.FIX_PRICE.equals(offer.getDiscountType())) {
// so the offer will not get selected.
return BigDecimal.valueOf(Integer.MAX_VALUE);
} else {
return BigDecimal.ZERO;
}
}
}
return offer.getValue();
}
Aggregations