Search in sources :

Example 11 with PromotionQualifier

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 12 with PromotionQualifier

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

Example 13 with PromotionQualifier

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;
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) 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