Search in sources :

Example 6 with PromotionDiscount

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());
        }
    }
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 7 with PromotionDiscount

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;
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 8 with PromotionDiscount

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);
}
Also used : PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 9 with PromotionDiscount

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;
}
Also used : Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Example 10 with PromotionDiscount

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;
}
Also used : Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)

Aggregations

PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)12 Offer (org.broadleafcommerce.core.offer.domain.Offer)7 PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)7 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)3 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)2 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)2 BigDecimal (java.math.BigDecimal)1 Money (org.broadleafcommerce.common.money.Money)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1