Search in sources :

Example 1 with AdvancedOffer

use of org.broadleafcommerce.core.offer.domain.AdvancedOffer 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();
}
Also used : OfferTier(org.broadleafcommerce.core.offer.domain.OfferTier) BeanComparator(org.apache.commons.beanutils.BeanComparator) AdvancedOffer(org.broadleafcommerce.core.offer.domain.AdvancedOffer)

Aggregations

BeanComparator (org.apache.commons.beanutils.BeanComparator)1 AdvancedOffer (org.broadleafcommerce.core.offer.domain.AdvancedOffer)1 OfferTier (org.broadleafcommerce.core.offer.domain.OfferTier)1