use of org.broadleafcommerce.core.offer.service.discount.PromotionDiscount 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.PromotionDiscount 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.PromotionDiscount in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method addPromotionDiscount.
@Override
public void addPromotionDiscount(PromotableCandidateItemOffer itemOffer, OfferItemCriteria itemCriteria, int qtyToMarkAsTarget) {
PromotionDiscount pd = lookupOrCreatePromotionDiscount(itemOffer);
if (pd == null) {
return;
}
pd.incrementQuantity(qtyToMarkAsTarget);
pd.setItemCriteria(itemCriteria);
pd.setCandidateItemOffer(itemOffer);
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionDiscount in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method lookupOrCreatePromotionDiscount.
public PromotionDiscount lookupOrCreatePromotionDiscount(PromotableCandidateItemOffer candidatePromotion) {
Offer promotion = candidatePromotion.getOffer();
for (PromotionDiscount pd : promotionDiscounts) {
if (pd.getPromotion().equals(promotion)) {
return pd;
}
}
PromotionDiscount pd = new PromotionDiscount();
pd.setPromotion(promotion);
promotionDiscounts.add(pd);
return pd;
}
use of org.broadleafcommerce.core.offer.service.discount.PromotionDiscount in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemPriceDetailImpl method splitIfNecessary.
@Override
public PromotableOrderItemPriceDetail splitIfNecessary() {
PromotableOrderItemPriceDetail returnDetail = null;
for (PromotionDiscount discount : promotionDiscounts) {
if (discount.getQuantity() != quantity) {
Long offerId = discount.getCandidateItemOffer().getOffer().getId();
Offer offer = discount.getCandidateItemOffer().getOffer();
return this.split(discount.getQuantity(), offerId, !CollectionUtils.isEmpty(offer.getQualifyingItemCriteriaXref()));
}
}
return returnDetail;
}
Aggregations