use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method getQuantityAvailableToBeUsedAsQualifier.
@Override
public int getQuantityAvailableToBeUsedAsQualifier(PromotableCandidateItemOffer itemOffer) {
int qtyAvailable = quantity;
Offer promotion = itemOffer.getOffer();
// Any quantities of this item that have already received the promotion are not eligible.
for (PromotionDiscount promotionDiscount : promotionDiscounts) {
if (promotionDiscount.getPromotion().equals(promotion) || restrictTarget(promotion, false)) {
qtyAvailable = qtyAvailable - promotionDiscount.getQuantity();
} else {
// Item's that receive other discounts might still be allowed to be qualifiers
if (restrictQualifier(promotionDiscount.getPromotion(), true)) {
qtyAvailable = qtyAvailable - promotionDiscount.getQuantity();
}
}
}
// another promotion that has a qualifier type of NONE or TARGET_ONLY cannot be used for this promotion
for (PromotionQualifier promotionQualifier : promotionQualifiers) {
if (promotionQualifier.getPromotion().equals(promotion) || restrictQualifier(promotion, false)) {
qtyAvailable = qtyAvailable - promotionQualifier.getQuantity();
} else {
if (restrictQualifier(promotionQualifier.getPromotion(), false)) {
qtyAvailable = qtyAvailable - promotionQualifier.getQuantity();
}
}
}
return qtyAvailable;
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method clearAllNonFinalizedQuantities.
@Override
public void clearAllNonFinalizedQuantities() {
Iterator<PromotionQualifier> promotionQualifierIterator = promotionQualifiers.iterator();
while (promotionQualifierIterator.hasNext()) {
PromotionQualifier promotionQualifier = promotionQualifierIterator.next();
if (promotionQualifier.getFinalizedQuantity() == 0) {
// If there are no quantities of this item that are finalized, then remove the item.
promotionQualifierIterator.remove();
} else {
// Otherwise, set the quantity to the number of finalized items.
promotionQualifier.setQuantity(promotionQualifier.getFinalizedQuantity());
}
}
Iterator<PromotionDiscount> promotionDiscountIterator = promotionDiscounts.iterator();
while (promotionDiscountIterator.hasNext()) {
PromotionDiscount promotionDiscount = promotionDiscountIterator.next();
if (promotionDiscount.getFinalizedQuantity() == 0) {
// If there are no quantities of this item that are finalized, then remove the item.
promotionDiscountIterator.remove();
} else {
// Otherwise, set the quantity to the number of finalized items.
promotionDiscount.setQuantity(promotionDiscount.getFinalizedQuantity());
}
}
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method addPromotionQualifier.
@Override
public PromotionQualifier addPromotionQualifier(PromotableCandidateItemOffer itemOffer, OfferItemCriteria itemCriteria, int qtyToMarkAsQualifier) {
PromotionQualifier pq = lookupOrCreatePromotionQualifier(itemOffer);
pq.incrementQuantity(qtyToMarkAsQualifier);
pq.setItemCriteria(itemCriteria);
return pq;
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method split.
protected PromotableOrderItemPriceDetail split(int discountQty, Long offerId, boolean hasQualifiers) {
int originalQty = quantity;
quantity = discountQty;
int splitItemQty = originalQty - discountQty;
// Create the new item with the correct quantity
PromotableOrderItemPriceDetail newDetail = promotableOrderItem.createNewDetail(splitItemQty);
// copy discounts
for (PromotionDiscount existingDiscount : promotionDiscounts) {
PromotionDiscount newDiscount = existingDiscount.split(discountQty);
if (newDiscount != null) {
newDetail.getPromotionDiscounts().add(newDiscount);
}
}
if (hasQualifiers) {
Iterator<PromotionQualifier> qualifiers = promotionQualifiers.iterator();
while (qualifiers.hasNext()) {
PromotionQualifier currentQualifier = qualifiers.next();
Long qualifierOfferId = currentQualifier.getPromotion().getId();
if (qualifierOfferId.equals(offerId) && currentQualifier.getQuantity() <= splitItemQty) {
// Remove this one from the original detail
qualifiers.remove();
newDetail.getPromotionQualifiers().add(currentQualifier);
} else {
PromotionQualifier newQualifier = currentQualifier.split(splitItemQty);
newDetail.getPromotionQualifiers().add(newQualifier);
}
}
}
for (PromotableOrderItemPriceDetailAdjustment existingAdjustment : promotableOrderItemPriceDetailAdjustments) {
PromotableOrderItemPriceDetailAdjustment newAdjustment = existingAdjustment.copy();
newDetail.addCandidateItemPriceDetailAdjustment(newAdjustment);
}
return newDetail;
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionQualifier 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);
}
Aggregations