Search in sources :

Example 1 with OfferDiscountType

use of org.broadleafcommerce.core.offer.service.type.OfferDiscountType in project BroadleafCommerce by BroadleafCommerce.

the class PromotableOfferUtility method computeAdjustmentValue.

public static Money computeAdjustmentValue(Money currentPriceDetailValue, BigDecimal offerUnitValue, OfferHolder offerHolder, PromotionRounding rounding) {
    Offer offer = offerHolder.getOffer();
    BroadleafCurrency currency = offerHolder.getCurrency();
    OfferDiscountType discountType = offer.getDiscountType();
    Money adjustmentValue;
    if (currency != null) {
        adjustmentValue = new Money(currency);
    } else {
        adjustmentValue = new Money();
    }
    if (OfferDiscountType.AMOUNT_OFF.equals(discountType)) {
        adjustmentValue = new Money(offerUnitValue, currency);
    }
    if (OfferDiscountType.FIX_PRICE.equals(discountType)) {
        adjustmentValue = currentPriceDetailValue.subtract(new Money(offerUnitValue, currency));
    }
    if (OfferDiscountType.PERCENT_OFF.equals(discountType)) {
        BigDecimal offerValue = currentPriceDetailValue.getAmount().multiply(offerUnitValue.divide(new BigDecimal("100"), 5, RoundingMode.HALF_EVEN));
        if (rounding.isRoundOfferValues()) {
            offerValue = offerValue.setScale(rounding.getRoundingScale(), rounding.getRoundingMode());
        }
        adjustmentValue = new Money(offerValue, currency);
    }
    if (currentPriceDetailValue.lessThan(adjustmentValue)) {
        adjustmentValue = currentPriceDetailValue;
    }
    return adjustmentValue;
}
Also used : Money(org.broadleafcommerce.common.money.Money) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) AdvancedOffer(org.broadleafcommerce.core.offer.domain.AdvancedOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferDiscountType(org.broadleafcommerce.core.offer.service.type.OfferDiscountType) BigDecimal(java.math.BigDecimal)

Example 2 with OfferDiscountType

use of org.broadleafcommerce.core.offer.service.type.OfferDiscountType in project BroadleafCommerce by BroadleafCommerce.

the class PromotableFulfillmentGroupAdjustmentImpl method computeAdjustmentValue.

protected Money computeAdjustmentValue(Money currentPriceDetailValue) {
    Offer offer = promotableCandidateFulfillmentGroupOffer.getOffer();
    OfferDiscountType discountType = offer.getDiscountType();
    Money adjustmentValue = new Money(getCurrency());
    if (OfferDiscountType.AMOUNT_OFF.equals(discountType)) {
        adjustmentValue = new Money(offer.getValue(), getCurrency());
    }
    if (OfferDiscountType.FIX_PRICE.equals(discountType)) {
        adjustmentValue = currentPriceDetailValue;
    }
    if (OfferDiscountType.PERCENT_OFF.equals(discountType)) {
        BigDecimal offerValue = currentPriceDetailValue.getAmount().multiply(offer.getValue().divide(new BigDecimal("100"), 5, RoundingMode.HALF_EVEN));
        if (isRoundOfferValues()) {
            offerValue = offerValue.setScale(roundingScale, roundingMode);
        }
        adjustmentValue = new Money(offerValue, getCurrency(), 5);
    }
    if (currentPriceDetailValue.lessThan(adjustmentValue)) {
        adjustmentValue = currentPriceDetailValue;
    }
    return adjustmentValue;
}
Also used : Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferDiscountType(org.broadleafcommerce.core.offer.service.type.OfferDiscountType) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)2 Money (org.broadleafcommerce.common.money.Money)2 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 OfferDiscountType (org.broadleafcommerce.core.offer.service.type.OfferDiscountType)2 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 AdvancedOffer (org.broadleafcommerce.core.offer.domain.AdvancedOffer)1