use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail 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);
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method markTargets.
/**
* Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.
* @param itemOffer
* @param order
* @return
*/
public boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier, boolean checkOnly) {
Offer promotion = itemOffer.getOffer();
if (itemOffer.getCandidateTargetsMap().keySet().isEmpty()) {
return false;
}
OrderItem relatedQualifierRoot = offerServiceUtilities.findRelatedQualifierRoot(relatedQualifier);
for (OfferItemCriteria itemCriteria : itemOffer.getCandidateTargetsMap().keySet()) {
List<PromotableOrderItem> promotableItems = itemOffer.getCandidateTargetsMap().get(itemCriteria);
List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
offerServiceUtilities.sortTargetItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
int targetQtyNeeded = itemCriteria.getQuantity();
// This code was added to support a requirement of buying at least "x" matching items
// but also applying the item to "x+1", "x+2", etc.
int minRequiredTargetQuantity = itemOffer.getMinimumRequiredTargetQuantity();
if (minRequiredTargetQuantity > 1 && minRequiredTargetQuantity > targetQtyNeeded) {
targetQtyNeeded = minRequiredTargetQuantity;
}
targetQtyNeeded = offerServiceUtilities.markTargetsForCriteria(itemOffer, relatedQualifier, checkOnly, promotion, relatedQualifierRoot, itemCriteria, priceDetails, targetQtyNeeded);
if (targetQtyNeeded != 0) {
return false;
}
}
if (!checkOnly) {
itemOffer.addUse();
}
return true;
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method markRelatedQualifiersAndTargets.
/**
* When the {@link Offer#getRequiresRelatedTargetAndQualifiers()} flag is set to true, we must make sure that we
* identify qualifiers and targets together, as they must be related to each other based on the
* {@link OrderItem#getParentOrderItem()} / {@link OrderItem#getChildOrderItems()} attributes.
*
* @param itemOffer
* @param order
* @return whether or not a suitable qualifier/target pair was found and marked
*/
protected boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
OrderItemHolder orderItemHolder = new OrderItemHolder(null);
for (Entry<OfferItemCriteria, List<PromotableOrderItem>> entry : itemOffer.getCandidateQualifiersMap().entrySet()) {
OfferItemCriteria itemCriteria = entry.getKey();
List<PromotableOrderItem> promotableItems = entry.getValue();
List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
int qualifierQtyNeeded = offerServiceUtilities.markRelatedQualifiersAndTargetsForItemCriteria(itemOffer, order, orderItemHolder, itemCriteria, priceDetails, this);
if (qualifierQtyNeeded != 0) {
return false;
}
}
return markTargets(itemOffer, order, orderItemHolder.getOrderItem(), false);
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorImpl method chooseSaleOrRetailAdjustments.
/**
* Some promotions can only apply to the retail price. This method determines whether
* retailPrice only promotions should be used instead of those that can apply to the sale
* price as well.
*
* @param order
* @return
*/
protected void chooseSaleOrRetailAdjustments(PromotableOrder order) {
List<PromotableOrderItemPriceDetail> itemPriceDetails = order.getAllPromotableOrderItemPriceDetails();
for (PromotableOrderItemPriceDetail itemDetail : itemPriceDetails) {
itemDetail.chooseSaleOrRetailAdjustments();
}
mergePriceDetails(order);
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method markQualifiersForCriteria.
@Override
public int markQualifiersForCriteria(PromotableCandidateItemOffer itemOffer, OfferItemCriteria itemCriteria, List<PromotableOrderItemPriceDetail> priceDetails) {
sortQualifierItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
// Calculate the number of qualifiers needed that will not receive the promotion.
// These will be reserved first before the target is assigned.
int qualifierQtyNeeded = itemCriteria.getQuantity();
for (PromotableOrderItemPriceDetail detail : priceDetails) {
// Mark Qualifiers
if (qualifierQtyNeeded > 0) {
int itemQtyAvailableToBeUsedAsQualifier = detail.getQuantityAvailableToBeUsedAsQualifier(itemOffer);
if (itemQtyAvailableToBeUsedAsQualifier > 0) {
int qtyToMarkAsQualifier = Math.min(qualifierQtyNeeded, itemQtyAvailableToBeUsedAsQualifier);
qualifierQtyNeeded -= qtyToMarkAsQualifier;
detail.addPromotionQualifier(itemOffer, itemCriteria, qtyToMarkAsQualifier);
}
}
if (qualifierQtyNeeded == 0) {
break;
}
}
return qualifierQtyNeeded;
}
Aggregations