Search in sources :

Example 61 with Money

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;
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) BigDecimal(java.math.BigDecimal)

Example 62 with Money

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);
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 63 with Money

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);
        }
    };
}
Also used : Money(org.broadleafcommerce.common.money.Money) Comparator(java.util.Comparator) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 64 with Money

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);
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 65 with Money

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) BigDecimal(java.math.BigDecimal)

Aggregations

Money (org.broadleafcommerce.common.money.Money)158 Order (org.broadleafcommerce.core.order.domain.Order)43 BigDecimal (java.math.BigDecimal)38 Offer (org.broadleafcommerce.core.offer.domain.Offer)29 Test (org.testng.annotations.Test)29 Transactional (org.springframework.transaction.annotation.Transactional)24 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)22 ArrayList (java.util.ArrayList)21 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)21 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)19 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 HashMap (java.util.HashMap)12 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)12 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)11 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)11 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)10