Search in sources :

Example 6 with PromotionQualifier

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

Example 7 with PromotionQualifier

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

Example 8 with PromotionQualifier

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

Example 9 with PromotionQualifier

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

Example 10 with PromotionQualifier

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);
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Aggregations

PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)13 PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)7 Offer (org.broadleafcommerce.core.offer.domain.Offer)5 Money (org.broadleafcommerce.common.money.Money)2 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)2 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)2 OrderItemQualifier (org.broadleafcommerce.core.order.domain.OrderItemQualifier)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)1 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1 OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)1