use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemImpl method getTotalAdjustmentValue.
@Override
public Money getTotalAdjustmentValue(boolean includeChildren) {
Money totalAdjustmentValue = BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
List<OrderItemPriceDetail> priceDetails = getOrderItemPriceDetails();
if (priceDetails != null) {
for (OrderItemPriceDetail priceDetail : getOrderItemPriceDetails()) {
totalAdjustmentValue = totalAdjustmentValue.add(priceDetail.getTotalAdjustmentValue());
}
}
if (includeChildren) {
for (OrderItem child : getChildOrderItems()) {
Money childPrice = child.getTotalAdjustmentValue();
totalAdjustmentValue = totalAdjustmentValue.add(childPrice);
}
}
return totalAdjustmentValue;
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class BundleOrderItemImpl method getRetailPrice.
@Override
public Money getRetailPrice() {
if (shouldSumItems()) {
Money bundleRetailPrice = BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
for (DiscreteOrderItem discreteOrderItem : discreteOrderItems) {
BigDecimal itemRetailPrice = discreteOrderItem.getRetailPrice().getAmount();
BigDecimal quantityPrice = itemRetailPrice.multiply(new BigDecimal(discreteOrderItem.getQuantity()));
bundleRetailPrice = bundleRetailPrice.add(BroadleafCurrencyUtils.getMoney(quantityPrice, getOrder().getCurrency()));
}
for (BundleOrderItemFeePrice fee : getBundleOrderItemFeePrices()) {
bundleRetailPrice = bundleRetailPrice.add(fee.getAmount());
}
return bundleRetailPrice;
} else {
return super.getRetailPrice();
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class BundleOrderItemImpl method getSalePrice.
@Override
public Money getSalePrice() {
if (shouldSumItems()) {
Money bundleSalePrice = null;
if (hasSaleItems()) {
bundleSalePrice = BroadleafCurrencyUtils.getMoney(getOrder().getCurrency());
for (DiscreteOrderItem discreteOrderItem : discreteOrderItems) {
BigDecimal itemSalePrice = null;
if (discreteOrderItem.getSalePrice() != null) {
itemSalePrice = discreteOrderItem.getSalePrice().getAmount();
} else {
itemSalePrice = discreteOrderItem.getRetailPrice().getAmount();
}
BigDecimal quantityPrice = itemSalePrice.multiply(new BigDecimal(discreteOrderItem.getQuantity()));
bundleSalePrice = bundleSalePrice.add(BroadleafCurrencyUtils.getMoney(quantityPrice, getOrder().getCurrency()));
}
for (BundleOrderItemFeePrice fee : getBundleOrderItemFeePrices()) {
bundleSalePrice = bundleSalePrice.add(fee.getAmount());
}
}
return bundleSalePrice;
} else {
return super.getSalePrice();
}
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorImpl method applyAllFulfillmentGroupOffers.
@Override
@SuppressWarnings("unchecked")
public boolean applyAllFulfillmentGroupOffers(List<PromotableCandidateFulfillmentGroupOffer> qualifiedFGOffers, PromotableOrder order) {
Map<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>> offerMap = new HashMap<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>>();
for (PromotableCandidateFulfillmentGroupOffer candidate : qualifiedFGOffers) {
FulfillmentGroupOfferPotential potential = new FulfillmentGroupOfferPotential();
potential.setOffer(candidate.getOffer());
if (offerMap.get(potential) == null) {
offerMap.put(potential, new ArrayList<PromotableCandidateFulfillmentGroupOffer>());
}
offerMap.get(potential).add(candidate);
}
List<FulfillmentGroupOfferPotential> potentials = new ArrayList<FulfillmentGroupOfferPotential>();
for (FulfillmentGroupOfferPotential potential : offerMap.keySet()) {
List<PromotableCandidateFulfillmentGroupOffer> fgOffers = offerMap.get(potential);
Collections.sort(fgOffers, new ReverseComparator(new BeanComparator("discountedAmount", new NullComparator())));
Collections.sort(fgOffers, new BeanComparator("priority", new NullComparator()));
if (potential.getOffer().isLimitedUsePerOrder() && fgOffers.size() > potential.getOffer().getMaxUsesPerOrder()) {
for (int j = potential.getOffer().getMaxUsesPerOrder(); j < fgOffers.size(); j++) {
fgOffers.remove(j);
}
}
filterOffersByQualifyingAndSubtotalRequirements(order, fgOffers);
for (PromotableCandidateFulfillmentGroupOffer candidate : fgOffers) {
if (potential.getTotalSavings().getAmount().equals(BankersRounding.zeroAmount())) {
BroadleafCurrency currency = order.getOrderCurrency();
if (currency != null) {
potential.setTotalSavings(new Money(BigDecimal.ZERO, currency.getCurrencyCode()));
} else {
potential.setTotalSavings(new Money(BigDecimal.ZERO));
}
}
Money priceBeforeAdjustments = candidate.getFulfillmentGroup().calculatePriceWithoutAdjustments();
Money discountedPrice = candidate.getDiscountedPrice();
potential.setTotalSavings(potential.getTotalSavings().add(priceBeforeAdjustments.subtract(discountedPrice)));
potential.setPriority(candidate.getOffer().getPriority());
}
potentials.add(potential);
}
// Sort fg potentials by priority and discount
Collections.sort(potentials, new BeanComparator("totalSavings", Collections.reverseOrder()));
Collections.sort(potentials, new BeanComparator("priority"));
potentials = removeTrailingNotCombinableFulfillmentGroupOffers(potentials);
boolean fgOfferApplied = false;
for (FulfillmentGroupOfferPotential potential : potentials) {
Offer offer = potential.getOffer();
boolean alreadyContainsTotalitarianOffer = order.isTotalitarianOfferApplied();
List<PromotableCandidateFulfillmentGroupOffer> candidates = offerMap.get(potential);
for (PromotableCandidateFulfillmentGroupOffer candidate : candidates) {
applyFulfillmentGroupOffer(candidate.getFulfillmentGroup(), candidate);
fgOfferApplied = true;
}
for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
fg.chooseSaleOrRetailAdjustments();
}
if ((offer.isTotalitarianOffer() != null && offer.isTotalitarianOffer()) || alreadyContainsTotalitarianOffer) {
fgOfferApplied = compareAndAdjustFulfillmentGroupOffers(order, fgOfferApplied);
if (fgOfferApplied) {
break;
}
} else if (!offer.isCombinableWithOtherOffers()) {
break;
}
}
return fgOfferApplied;
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorImpl method calculateFulfillmentGroupTotal.
@Override
public void calculateFulfillmentGroupTotal(PromotableOrder order) {
Money totalFulfillmentCharges = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getOrderCurrency());
for (PromotableFulfillmentGroup fulfillmentGroupMember : order.getFulfillmentGroups()) {
FulfillmentGroup fulfillmentGroup = fulfillmentGroupMember.getFulfillmentGroup();
Money fulfillmentCharges;
if (fulfillmentGroup.getShippingOverride()) {
fulfillmentCharges = fulfillmentGroup.getFulfillmentPrice();
} else {
fulfillmentCharges = fulfillmentGroupMember.getFinalizedPriceWithAdjustments();
fulfillmentGroupMember.getFulfillmentGroup().setFulfillmentPrice(fulfillmentCharges);
}
totalFulfillmentCharges = totalFulfillmentCharges.add(fulfillmentCharges);
}
order.setTotalFufillmentCharges(totalFulfillmentCharges);
}
Aggregations