use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderAdjustmentImpl method computeAdjustmentValue.
/*
* Calculates the value of the adjustment by first getting the current value of the order and then
* calculating the value of this adjustment.
*
* If this adjustment value is greater than the currentOrderValue (e.g. would make the order go negative
* then the adjustment value is set to the value of the order).
*/
protected void computeAdjustmentValue() {
adjustmentValue = new Money(promotableOrder.getOrderCurrency());
Money currentOrderValue = promotableOrder.calculateSubtotalWithAdjustments();
// We also need to consider order offers that have been applied when figuring out if the current value of this
// adjustment will be more than the current subtotal of the order
currentOrderValue = currentOrderValue.subtract(promotableOrder.calculateOrderAdjustmentTotal());
// Note: FIXED_PRICE not calculated as this is not a valid option for offers.
if (offer.getDiscountType().equals(OfferDiscountType.AMOUNT_OFF)) {
adjustmentValue = new Money(offer.getValue(), promotableOrder.getOrderCurrency());
} else if (offer.getDiscountType().equals(OfferDiscountType.PERCENT_OFF)) {
BigDecimal offerValue = currentOrderValue.getAmount().multiply(offer.getValue().divide(new BigDecimal("100"), 5, RoundingMode.HALF_EVEN));
if (isRoundOfferValues()) {
offerValue = offerValue.setScale(roundingScale, roundingMode);
}
adjustmentValue = new Money(offerValue, promotableOrder.getOrderCurrency(), 5);
}
if (currentOrderValue.lessThan(adjustmentValue)) {
adjustmentValue = currentOrderValue;
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderImpl method setOrderSubTotalToPriceWithAdjustments.
@Override
public void setOrderSubTotalToPriceWithAdjustments() {
Money calculatedSubTotal = calculateSubtotalWithAdjustments();
order.setSubTotal(calculatedSubTotal);
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method getPromotableItemComparator.
protected Comparator<PromotableOrderItemPriceDetail> getPromotableItemComparator(final boolean applyToSalePrice) {
return new Comparator<PromotableOrderItemPriceDetail>() {
@Override
public int compare(PromotableOrderItemPriceDetail o1, PromotableOrderItemPriceDetail o2) {
Money price = o1.getPromotableOrderItem().getPriceBeforeAdjustments(applyToSalePrice);
Money price2 = o2.getPromotableOrderItem().getPriceBeforeAdjustments(applyToSalePrice);
// highest amount first
return price2.compareTo(price);
}
};
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method chooseSaleOrRetailAdjustments.
/**
* This method will check to see if the salePriceAdjustments or retailPriceAdjustments are better
* and remove those that should not apply.
* @return
*/
public void chooseSaleOrRetailAdjustments() {
adjustmentsFinalized = true;
adjustedTotal = null;
this.useSaleAdjustments = Boolean.FALSE;
Money salePriceBeforeAdjustments = promotableOrderItem.getSalePriceBeforeAdjustments();
Money retailPriceBeforeAdjustments = promotableOrderItem.getRetailPriceBeforeAdjustments();
if (hasOrderItemAdjustments()) {
Money saleAdjustmentPrice = calculateSaleAdjustmentUnitPrice();
Money retailAdjustmentPrice = calculateRetailAdjustmentUnitPrice();
if (promotableOrderItem.isOnSale()) {
if (saleAdjustmentPrice.lessThanOrEqual(retailAdjustmentPrice)) {
this.useSaleAdjustments = Boolean.TRUE;
adjustedTotal = saleAdjustmentPrice;
} else {
adjustedTotal = retailAdjustmentPrice;
}
if (!adjustedTotal.lessThan(salePriceBeforeAdjustments)) {
// Adjustments are not as good as the sale price. So, clear them and use the sale price.
promotableOrderItemPriceDetailAdjustments.clear();
adjustedTotal = salePriceBeforeAdjustments;
}
} else {
if (!retailAdjustmentPrice.lessThan(promotableOrderItem.getRetailPriceBeforeAdjustments())) {
// Adjustments are not as good as the retail price.
promotableOrderItemPriceDetailAdjustments.clear();
adjustedTotal = retailPriceBeforeAdjustments;
} else {
adjustedTotal = retailAdjustmentPrice;
}
}
if (useSaleAdjustments) {
removeRetailOnlyAdjustments();
}
removeZeroDollarAdjustments(useSaleAdjustments);
finalizeAdjustments(useSaleAdjustments);
}
if (adjustedTotal == null) {
if (salePriceBeforeAdjustments != null) {
this.useSaleAdjustments = true;
adjustedTotal = salePriceBeforeAdjustments;
} else {
adjustedTotal = retailPriceBeforeAdjustments;
}
}
adjustedTotal = adjustedTotal.multiply(quantity);
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class PromotableCandidateFulfillmentGroupOfferImpl method computeDiscountedAmount.
@Override
public Money computeDiscountedAmount() {
Money discountedAmount = new Money(0);
Money priceToUse = getBasePrice();
if (priceToUse != null) {
if (offer.getDiscountType().equals(OfferDiscountType.AMOUNT_OFF)) {
discountedAmount = BroadleafCurrencyUtils.getMoney(offer.getValue(), promotableFulfillmentGroup.getFulfillmentGroup().getOrder().getCurrency());
} else if (offer.getDiscountType().equals(OfferDiscountType.FIX_PRICE)) {
discountedAmount = priceToUse.subtract(BroadleafCurrencyUtils.getMoney(offer.getValue(), promotableFulfillmentGroup.getFulfillmentGroup().getOrder().getCurrency()));
} else if (offer.getDiscountType().equals(OfferDiscountType.PERCENT_OFF)) {
discountedAmount = priceToUse.multiply(offer.getValue().divide(new BigDecimal("100")));
}
if (discountedAmount.greaterThan(priceToUse)) {
discountedAmount = priceToUse;
}
}
return discountedAmount;
}
Aggregations