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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations