use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier 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.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method copyWithFinalizedData.
@Override
public PromotableOrderItemPriceDetail copyWithFinalizedData() {
PromotableOrderItemPriceDetail copyDetail = promotableOrderItem.createNewDetail(quantity);
for (PromotionDiscount existingDiscount : promotionDiscounts) {
if (existingDiscount.isFinalized()) {
PromotionDiscount newDiscount = existingDiscount.copy();
copyDetail.getPromotionDiscounts().add(newDiscount);
}
}
for (PromotionQualifier existingQualifier : promotionQualifiers) {
if (existingQualifier.isFinalized()) {
PromotionQualifier newQualifier = existingQualifier.copy();
copyDetail.getPromotionQualifiers().add(newQualifier);
}
}
for (PromotableOrderItemPriceDetailAdjustment existingAdjustment : promotableOrderItemPriceDetailAdjustments) {
PromotableOrderItemPriceDetailAdjustment newAdjustment = existingAdjustment.copy();
copyDetail.addCandidateItemPriceDetailAdjustment(newAdjustment);
}
return copyDetail;
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method markRelatedQualifiersAndTargetsForItemCriteria.
@Override
public int markRelatedQualifiersAndTargetsForItemCriteria(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItemHolder orderItemHolder, OfferItemCriteria itemCriteria, List<PromotableOrderItemPriceDetail> priceDetails, ItemOfferMarkTargets itemOfferMarkTargets) {
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) {
OrderItem oi = detail.getPromotableOrderItem().getOrderItem();
if (qualifierQtyNeeded > 0) {
int itemQtyAvailableToBeUsedAsQualifier = detail.getQuantityAvailableToBeUsedAsQualifier(itemOffer);
if (itemQtyAvailableToBeUsedAsQualifier > 0) {
// We have found a qualifier that meets this offer criteria. First, we'll save some state that we
// might need in the future.
OfferItemCriteria previousQualifierCriteria = null;
for (PromotionQualifier possibleQualifier : detail.getPromotionQualifiers()) {
if (possibleQualifier.getPromotion().equals(itemOffer.getOffer())) {
previousQualifierCriteria = possibleQualifier.getItemCriteria();
break;
}
}
// Go ahead and mark this item as a qualifier
int qtyToMarkAsQualifier = Math.min(qualifierQtyNeeded, itemQtyAvailableToBeUsedAsQualifier);
qualifierQtyNeeded -= qtyToMarkAsQualifier;
PromotionQualifier pq = detail.addPromotionQualifier(itemOffer, itemCriteria, qtyToMarkAsQualifier);
pq.setPrice(detail.getPromotableOrderItem().getPriceBeforeAdjustments(itemOffer.getOffer().getApplyDiscountToSalePrice()));
// that there is an eligible target(s) and continue on.
if (itemOfferMarkTargets.markTargets(itemOffer, order, oi, true)) {
// We found a target. Let's save this related order item used as the qualifier in case
// we succeed
orderItemHolder.setOrderItem(oi);
} else {
// If we didn't find a target, we need to roll back how we marked this item as a qualifier.
qualifierQtyNeeded += qtyToMarkAsQualifier;
if (pq.getQuantity() == qtyToMarkAsQualifier) {
detail.getPromotionQualifiers().remove(pq);
} else {
pq.setItemCriteria(previousQualifierCriteria);
pq.setQuantity(pq.getQuantity() - qtyToMarkAsQualifier);
}
}
}
}
if (qualifierQtyNeeded == 0) {
break;
}
}
return qualifierQtyNeeded;
}
Aggregations