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;
}
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;
}
Aggregations