Search in sources :

Example 86 with Money

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

the class ItemOfferProcessorImpl method calculateWeightedPercent.

protected BigDecimal calculateWeightedPercent(PromotionDiscount discount, PromotableOrderItem item, Money itemSavings) {
    Money effectedItemsSubtotal = discount.getCandidateItemOffer().getOriginalPrice();
    for (PromotableOrderItemPriceDetail itemPriceDetail : item.getPromotableOrderItemPriceDetails()) {
        for (PromotionQualifier qualifierDetail : itemPriceDetail.getPromotionQualifiers()) {
            Integer qualifierQuantity = qualifierDetail.getFinalizedQuantity();
            effectedItemsSubtotal = effectedItemsSubtotal.add(qualifierDetail.getPrice().multiply(qualifierQuantity));
        }
    }
    return calculatePercent(effectedItemsSubtotal, itemSavings);
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 87 with Money

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

the class ItemOfferProcessorImpl method determineBestPermutation.

protected List<PromotableCandidateItemOffer> determineBestPermutation(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order) {
    List<List<PromotableCandidateItemOffer>> permutations = buildItemOfferPermutations(itemOffers);
    removeDuplicatePermutations(permutations);
    List<PromotableCandidateItemOffer> bestOfferList = null;
    Money lowestSubtotal = null;
    if (permutations.size() > 1) {
        for (List<PromotableCandidateItemOffer> offerList : permutations) {
            for (PromotableCandidateItemOffer offer : offerList) {
                offer.resetUses();
            }
            applyAllItemOffers(offerList, order);
            chooseSaleOrRetailAdjustments(order);
            Money testSubtotal = order.calculateSubtotalWithAdjustments();
            if (lowestSubtotal == null || testSubtotal.lessThan(lowestSubtotal)) {
                lowestSubtotal = testSubtotal;
                bestOfferList = offerList;
            }
            // clear price details
            for (PromotableOrderItem item : order.getDiscountableOrderItems()) {
                item.resetPriceDetails();
            }
        }
    } else {
        bestOfferList = permutations.get(0);
    }
    for (PromotableCandidateItemOffer offer : bestOfferList) {
        offer.resetUses();
    }
    return bestOfferList;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) ArrayList(java.util.ArrayList) List(java.util.List) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 88 with Money

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

the class BundleOrderItemImpl method getTaxablePrice.

@Override
public Money getTaxablePrice() {
    if (shouldSumItems()) {
        Money currentBundleTaxablePrice = BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
        for (DiscreteOrderItem discreteOrderItem : discreteOrderItems) {
            BigDecimal currentItemTaxablePrice = discreteOrderItem.getTaxablePrice().getAmount();
            BigDecimal priceWithQuantity = currentItemTaxablePrice.multiply(new BigDecimal(discreteOrderItem.getQuantity()));
            currentBundleTaxablePrice = currentBundleTaxablePrice.add(BroadleafCurrencyUtils.getMoney(priceWithQuantity, getOrder().getCurrency()));
        }
        for (BundleOrderItemFeePrice fee : getBundleOrderItemFeePrices()) {
            if (fee.isTaxable()) {
                currentBundleTaxablePrice = currentBundleTaxablePrice.add(fee.getAmount());
            }
        }
        return currentBundleTaxablePrice;
    } else {
        return super.getTaxablePrice();
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) BigDecimal(java.math.BigDecimal)

Example 89 with Money

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

the class DiscreteOrderItemImpl method setSku.

@Override
public void setSku(Sku sku) {
    this.sku = sku;
    Money retail = sku.getBaseRetailPrice();
    if (retail != null) {
        this.baseRetailPrice = retail.getAmount();
    }
    Money sale = sku.getBaseSalePrice();
    if (sale != null) {
        this.baseSalePrice = sale.getAmount();
    }
    this.itemTaxable = sku.isTaxable();
    setName(sku.getName());
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 90 with Money

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

the class DiscreteOrderItemImpl method updateSalePrice.

protected boolean updateSalePrice() {
    if (isSalePriceOverride()) {
        return false;
    }
    Money skuSalePrice = null;
    DynamicSkuPrices priceData = getSku().getPriceData();
    if (priceData != null) {
        skuSalePrice = priceData.getPriceForQuantity(quantity);
    }
    if (skuSalePrice == null) {
        skuSalePrice = getSku().getSalePrice();
    }
    // Override retail/sale prices from skuBundle.
    if (skuBundleItem != null) {
        if (skuBundleItem.getSalePrice() != null) {
            skuSalePrice = skuBundleItem.getSalePrice();
        }
    }
    boolean updated = false;
    // use the sku prices - the retail and sale prices could be null
    if (skuSalePrice != null && !skuSalePrice.getAmount().equals(salePrice)) {
        baseSalePrice = skuSalePrice.getAmount();
        salePrice = skuSalePrice.getAmount();
        updated = true;
    }
    // If there is no more sale price (because it got removed) then detect that case as well
    if (skuSalePrice == null && salePrice != null) {
        baseSalePrice = null;
        salePrice = null;
        updated = true;
    }
    // Adjust prices by adding in fees if they are attached.
    if (getDiscreteOrderItemFeePrices() != null) {
        for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
            Money returnPrice = convertToMoney(salePrice);
            if (returnPrice != null) {
                salePrice = returnPrice.add(fee.getAmount()).getAmount();
            }
        }
    }
    return updated;
}
Also used : Money(org.broadleafcommerce.common.money.Money) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices)

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