Search in sources :

Example 91 with Money

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

the class DiscreteOrderItemImpl method updateRetailPrice.

protected boolean updateRetailPrice() {
    if (isRetailPriceOverride()) {
        return false;
    }
    Money skuRetailPrice = getSku().getRetailPrice();
    // Override retail/sale prices from skuBundle.
    if (skuBundleItem != null) {
        if (skuBundleItem.getRetailPrice() != null) {
            skuRetailPrice = skuBundleItem.getRetailPrice();
        }
    }
    boolean updated = false;
    // use the sku prices - the retail and sale prices could be null
    if (skuRetailPrice != null && !skuRetailPrice.getAmount().equals(retailPrice)) {
        baseRetailPrice = skuRetailPrice.getAmount();
        retailPrice = skuRetailPrice.getAmount();
        updated = true;
    }
    // Adjust prices by adding in fees if they are attached.
    if (getDiscreteOrderItemFeePrices() != null) {
        for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
            Money returnPrice = convertToMoney(retailPrice);
            retailPrice = returnPrice.add(fee.getAmount()).getAmount();
        }
    }
    return updated;
}
Also used : Money(org.broadleafcommerce.common.money.Money)

Example 92 with Money

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

the class PromotableOrderItemPriceDetailAdjustmentImpl method computeAdjustmentValues.

/*
     * Calculates the value of the adjustment for both retail and sale prices.   
     * If either adjustment is greater than the item value, it will be set to the
     * currentItemValue (e.g. no adjustment can cause a negative value). 
     */
protected void computeAdjustmentValues() {
    saleAdjustmentValue = new Money(getCurrency());
    retailAdjustmentValue = new Money(getCurrency());
    Money currentPriceDetailRetailValue = promotableOrderItemPriceDetail.calculateItemUnitPriceWithAdjustments(false);
    Money currentPriceDetailSalesValue = promotableOrderItemPriceDetail.calculateItemUnitPriceWithAdjustments(true);
    if (currentPriceDetailSalesValue == null) {
        currentPriceDetailSalesValue = currentPriceDetailRetailValue;
    }
    BigDecimal offerUnitValue = PromotableOfferUtility.determineOfferUnitValue(offer, promotableCandidateItemOffer);
    retailAdjustmentValue = PromotableOfferUtility.computeAdjustmentValue(currentPriceDetailRetailValue, offerUnitValue, this, this);
    if (offer.getApplyDiscountToSalePrice() == true) {
        saleAdjustmentValue = PromotableOfferUtility.computeAdjustmentValue(currentPriceDetailSalesValue, offerUnitValue, this, this);
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) BigDecimal(java.math.BigDecimal)

Example 93 with Money

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

the class PromotableOrderItemPriceDetailImpl method lookupOrCreatePromotionQualifier.

public PromotionQualifier lookupOrCreatePromotionQualifier(PromotableCandidateItemOffer candidatePromotion) {
    Offer promotion = candidatePromotion.getOffer();
    for (PromotionQualifier pq : promotionQualifiers) {
        if (pq.getPromotion().equals(promotion)) {
            return pq;
        }
    }
    PromotionQualifier pq = new PromotionQualifier();
    Money pqPriceBeforeAdjustment = new Money(0);
    for (Map.Entry<OfferItemCriteria, List<PromotableOrderItem>> qualifierMapEntry : candidatePromotion.getCandidateQualifiersMap().entrySet()) {
        for (PromotableOrderItem promotableOrderItem : qualifierMapEntry.getValue()) {
            Money priceBeforeAdjustments = promotableOrderItem.getOrderItem().getPriceBeforeAdjustments(candidatePromotion.getOffer().getApplyDiscountToSalePrice());
            pqPriceBeforeAdjustment = pqPriceBeforeAdjustment.add(priceBeforeAdjustments);
        }
    }
    pq.setPrice(pqPriceBeforeAdjustment);
    pq.setPromotion(promotion);
    promotionQualifiers.add(pq);
    return pq;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 94 with Money

use of org.broadleafcommerce.common.money.Money 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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferDiscountType(org.broadleafcommerce.core.offer.service.type.OfferDiscountType) BigDecimal(java.math.BigDecimal)

Example 95 with Money

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

the class PromotableFulfillmentGroupAdjustmentImpl method computeAdjustmentValues.

/*
     * Calculates the value of the adjustment for both retail and sale prices.   
     * If either adjustment is greater than the item value, it will be set to the
     * currentItemValue (e.g. no adjustment can cause a negative value). 
     */
protected void computeAdjustmentValues() {
    saleAdjustmentValue = new Money(getCurrency());
    retailAdjustmentValue = new Money(getCurrency());
    Offer offer = promotableCandidateFulfillmentGroupOffer.getOffer();
    Money currentPriceDetailSalesValue = promotableFulfillmentGroup.calculatePriceWithAdjustments(true);
    Money currentPriceDetailRetailValue = promotableFulfillmentGroup.calculatePriceWithAdjustments(false);
    retailAdjustmentValue = PromotableOfferUtility.computeAdjustmentValue(currentPriceDetailRetailValue, offer.getValue(), this, this);
    if (offer.getApplyDiscountToSalePrice() == true) {
        saleAdjustmentValue = PromotableOfferUtility.computeAdjustmentValue(currentPriceDetailSalesValue, offer.getValue(), this, this);
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer)

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