Search in sources :

Example 56 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupOfferProcessorImpl method compareAndAdjustFulfillmentGroupOffers.

protected boolean compareAndAdjustFulfillmentGroupOffers(PromotableOrder order, boolean fgOfferApplied) {
    Money regularOrderDiscountShippingTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getOrderCurrency());
    regularOrderDiscountShippingTotal = regularOrderDiscountShippingTotal.add(order.calculateSubtotalWithoutAdjustments());
    for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
        regularOrderDiscountShippingTotal = regularOrderDiscountShippingTotal.add(fg.getFinalizedPriceWithAdjustments());
    }
    Money discountOrderRegularShippingTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getOrderCurrency());
    discountOrderRegularShippingTotal = discountOrderRegularShippingTotal.add(order.calculateSubtotalWithAdjustments());
    for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
        discountOrderRegularShippingTotal = discountOrderRegularShippingTotal.add(fg.calculatePriceWithoutAdjustments());
    }
    if (discountOrderRegularShippingTotal.lessThan(regularOrderDiscountShippingTotal)) {
        // order/item offer is better; remove totalitarian fulfillment group offer and process other fg offers
        order.removeAllCandidateFulfillmentOfferAdjustments();
        fgOfferApplied = false;
    } else {
        // totalitarian fg offer is better; remove all order/item offers
        order.removeAllCandidateOrderOfferAdjustments();
        order.removeAllCandidateItemOfferAdjustments();
        order.getOrder().setSubTotal(order.calculateSubtotalWithAdjustments());
    }
    return fgOfferApplied;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)

Example 57 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class ItemOfferProcessorImpl method calculatePotentialSavings.

/**
 * This method determines the potential savings for each item offer as if it was the only item offer being applied.
 * @param itemOffers
 * @param order
 */
protected void calculatePotentialSavings(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order) {
    if (itemOffers.size() > 1) {
        for (PromotableCandidateItemOffer itemOffer : itemOffers) {
            Money potentialSavings = new Money(order.getOrderCurrency());
            Offer offer = itemOffer.getOffer();
            BigDecimal calculatedWeightedPercent = new BigDecimal(0);
            markQualifiersAndTargets(order, itemOffer);
            for (PromotableOrderItemPriceDetail detail : order.getAllPromotableOrderItemPriceDetails()) {
                PromotableOrderItem item = detail.getPromotableOrderItem();
                for (PromotionDiscount discount : detail.getPromotionDiscounts()) {
                    Money itemSavings = calculatePotentialSavingsForOrderItem(itemOffer, item, discount.getQuantity());
                    potentialSavings = potentialSavings.add(itemSavings);
                    if (useCalculatePercent(offer)) {
                        BigDecimal discountPercent = calculatePercent(item.calculateTotalWithoutAdjustments(), itemSavings);
                        calculatedWeightedPercent = calculatedWeightedPercent.add(discountPercent);
                    } else if (hasQualifierAndQualifierRestricted(offer)) {
                        BigDecimal discountPercent = calculateWeightedPercent(discount, item, itemSavings);
                        calculatedWeightedPercent = calculatedWeightedPercent.add(discountPercent);
                    }
                }
                // Reset state back for next offer
                detail.getPromotionDiscounts().clear();
                detail.getPromotionQualifiers().clear();
            }
            itemOffer.setPotentialSavings(potentialSavings);
            if (usePercentOffValue(offer)) {
                itemOffer.setWeightedPercentSaved(offer.getValue());
            } else if (useCalculatePercent(offer) || hasQualifierAndQualifierRestricted(offer)) {
                itemOffer.setWeightedPercentSaved(calculatedWeightedPercent);
            }
            if (itemOffer.getUses() == 0) {
                itemOffer.setPotentialSavingsQtyOne(potentialSavings);
            } else {
                itemOffer.setPotentialSavingsQtyOne(potentialSavings.divide(itemOffer.getUses()));
            }
        }
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) BigDecimal(java.math.BigDecimal) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 58 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method compareAndAdjustOrderAndItemOffers.

/**
 * Called when the system must determine whether to apply order or item adjustments.
 * @param promotableOrder
 * @param orderOffersApplied
 */
protected void compareAndAdjustOrderAndItemOffers(PromotableOrder promotableOrder) {
    Money orderAdjustmentTotal = promotableOrder.calculateOrderAdjustmentTotal();
    Money itemAdjustmentTotal = promotableOrder.calculateItemAdjustmentTotal();
    if (orderAdjustmentTotal.greaterThanOrEqual(itemAdjustmentTotal)) {
        promotableOrder.removeAllCandidateItemOfferAdjustments();
    } else {
        promotableOrder.removeAllCandidateOrderOfferAdjustments();
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 59 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class PromotableFulfillmentGroupImpl 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() {
    this.useSaleAdjustments = Boolean.FALSE;
    Money saleAdjustmentPrice = calculateSaleAdjustmentPrice();
    Money retailAdjustmentPrice = calculateRetailAdjustmentPrice();
    if (saleAdjustmentPrice.lessThan(retailAdjustmentPrice)) {
        this.useSaleAdjustments = Boolean.TRUE;
        adjustedPrice = saleAdjustmentPrice;
    } else {
        adjustedPrice = retailAdjustmentPrice;
    }
    if (useSaleAdjustments) {
        removeRetailOnlyAdjustments();
    }
    removeZeroDollarAdjustments(useSaleAdjustments);
    finalizeAdjustments(useSaleAdjustments);
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 60 with Money

use of org.broadleafcommerce.common.money.Money 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)

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