Search in sources :

Example 6 with OfferItemCriteria

use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.

the class ItemOfferProcessorImpl method markQualifiers.

/**
 * Loop through ItemCriteria and mark qualifiers required to give the promotion to 1 or more targets.
 * @param itemOffer
 * @param order
 * @return
 */
protected boolean markQualifiers(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
    for (OfferItemCriteria itemCriteria : itemOffer.getCandidateQualifiersMap().keySet()) {
        List<PromotableOrderItem> promotableItems = itemOffer.getCandidateQualifiersMap().get(itemCriteria);
        List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
        int qualifierQtyNeeded = offerServiceUtilities.markQualifiersForCriteria(itemOffer, itemCriteria, priceDetails);
        if (qualifierQtyNeeded != 0) {
            return false;
        }
    }
    return true;
}
Also used : OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 7 with OfferItemCriteria

use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.

the class ItemOfferProcessorImpl method markTargets.

/**
 * Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.
 * @param itemOffer
 * @param order
 * @return
 */
public boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier, boolean checkOnly) {
    Offer promotion = itemOffer.getOffer();
    if (itemOffer.getCandidateTargetsMap().keySet().isEmpty()) {
        return false;
    }
    OrderItem relatedQualifierRoot = offerServiceUtilities.findRelatedQualifierRoot(relatedQualifier);
    for (OfferItemCriteria itemCriteria : itemOffer.getCandidateTargetsMap().keySet()) {
        List<PromotableOrderItem> promotableItems = itemOffer.getCandidateTargetsMap().get(itemCriteria);
        List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
        offerServiceUtilities.sortTargetItemDetails(priceDetails, itemOffer.getOffer().getApplyDiscountToSalePrice());
        int targetQtyNeeded = itemCriteria.getQuantity();
        // This code was added to support a requirement of buying at least "x" matching items
        // but also applying the item to "x+1", "x+2", etc.
        int minRequiredTargetQuantity = itemOffer.getMinimumRequiredTargetQuantity();
        if (minRequiredTargetQuantity > 1 && minRequiredTargetQuantity > targetQtyNeeded) {
            targetQtyNeeded = minRequiredTargetQuantity;
        }
        targetQtyNeeded = offerServiceUtilities.markTargetsForCriteria(itemOffer, relatedQualifier, checkOnly, promotion, relatedQualifierRoot, itemCriteria, priceDetails, targetQtyNeeded);
        if (targetQtyNeeded != 0) {
            return false;
        }
    }
    if (!checkOnly) {
        itemOffer.addUse();
    }
    return true;
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 8 with OfferItemCriteria

use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.

the class ItemOfferProcessorImpl method markRelatedQualifiersAndTargets.

/**
 * When the {@link Offer#getRequiresRelatedTargetAndQualifiers()} flag is set to true, we must make sure that we
 * identify qualifiers and targets together, as they must be related to each other based on the
 * {@link OrderItem#getParentOrderItem()} / {@link OrderItem#getChildOrderItems()} attributes.
 *
 * @param itemOffer
 * @param order
 * @return whether or not a suitable qualifier/target pair was found and marked
 */
protected boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order) {
    OrderItemHolder orderItemHolder = new OrderItemHolder(null);
    for (Entry<OfferItemCriteria, List<PromotableOrderItem>> entry : itemOffer.getCandidateQualifiersMap().entrySet()) {
        OfferItemCriteria itemCriteria = entry.getKey();
        List<PromotableOrderItem> promotableItems = entry.getValue();
        List<PromotableOrderItemPriceDetail> priceDetails = buildPriceDetailListFromOrderItems(promotableItems);
        int qualifierQtyNeeded = offerServiceUtilities.markRelatedQualifiersAndTargetsForItemCriteria(itemOffer, order, orderItemHolder, itemCriteria, priceDetails, this);
        if (qualifierQtyNeeded != 0) {
            return false;
        }
    }
    return markTargets(itemOffer, order, orderItemHolder.getOrderItem(), false);
}
Also used : OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) ArrayList(java.util.ArrayList) List(java.util.List) OrderItemHolder(org.broadleafcommerce.core.order.domain.dto.OrderItemHolder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 9 with OfferItemCriteria

use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria 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 10 with OfferItemCriteria

use of org.broadleafcommerce.core.offer.domain.OfferItemCriteria in project BroadleafCommerce by BroadleafCommerce.

the class PricingTest method createOffer.

private Offer createOffer(String offerName, OfferType offerType, OfferDiscountType discountType, double value, String customerRule, String orderRule) {
    Offer offer = new OfferImpl();
    offer.setName(offerName);
    offer.setStartDate(SystemTime.asDate());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    offer.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 2);
    offer.setEndDate(calendar.getTime());
    offer.setType(offerType);
    offer.setDiscountType(discountType);
    offer.setValue(BigDecimal.valueOf(value));
    offer.setAutomaticallyAdded(true);
    OfferItemCriteria oic = new OfferItemCriteriaImpl();
    oic.setQuantity(1);
    oic.setMatchRule(orderRule);
    OfferTargetCriteriaXref targetXref = new OfferTargetCriteriaXrefImpl();
    targetXref.setOffer(offer);
    targetXref.setOfferItemCriteria(oic);
    offer.setTargetItemCriteriaXref(Collections.singleton(targetXref));
    offer.setCombinableWithOtherOffers(true);
    offer = offerService.save(offer);
    offer.setMaxUsesPerOrder(50);
    return offer;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) OfferTargetCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) Calendar(java.util.Calendar) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) OfferTargetCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)

Aggregations

OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)14 Offer (org.broadleafcommerce.core.offer.domain.Offer)9 OfferItemCriteriaImpl (org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl)7 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 HashSet (java.util.HashSet)5 OfferQualifyingCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)5 OfferQualifyingCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl)5 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)4 ArrayList (java.util.ArrayList)3 Money (org.broadleafcommerce.common.money.Money)3 OfferTargetCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)3 OfferTargetCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl)3 Calendar (java.util.Calendar)2 List (java.util.List)2 PromotionQualifier (org.broadleafcommerce.core.offer.service.discount.PromotionQualifier)2 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 Map (java.util.Map)1 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)1 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)1