Search in sources :

Example 1 with OfferItemCriteria

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

the class OfferDataItemProvider method createItemBasedOfferWithItemCriteria.

public List<Offer> createItemBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String qualRule, String targetRule) {
    List<Offer> offers = createItemBasedOffer(orderRule, targetRule, discountType);
    if (qualRule != null) {
        Offer firstOffer = offers.get(0);
        OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
        // qualCriteria.setQualifyingOffer(offers.get(0));
        qualCriteria.setQuantity(1);
        qualCriteria.setMatchRule(qualRule);
        Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
        OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
        xref.setOffer(firstOffer);
        xref.setOfferItemCriteria(qualCriteria);
        criterias.add(xref);
        firstOffer.setQualifyingItemCriteriaXref(criterias);
    }
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 2 with OfferItemCriteria

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

the class OfferDataItemProvider method createOrderBasedOfferWithItemCriteria.

public List<Offer> createOrderBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String orderItemMatchRule) {
    List<Offer> offers = createOrderBasedOffer(orderRule, discountType);
    Offer firstOffer = offers.get(0);
    OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
    // qualCriteria.setQualifyingOffer(offers.get(0));
    qualCriteria.setQuantity(1);
    qualCriteria.setMatchRule(orderItemMatchRule);
    Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
    OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
    xref.setOffer(firstOffer);
    xref.setOfferItemCriteria(qualCriteria);
    criterias.add(xref);
    firstOffer.setQualifyingItemCriteriaXref(criterias);
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 3 with OfferItemCriteria

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

the class OfferDataItemProvider method createFGBasedOfferWithItemCriteria.

public List<Offer> createFGBasedOfferWithItemCriteria(String orderRule, String fgRule, OfferDiscountType discountType, String orderItemMatchRule) {
    List<Offer> offers = createFGBasedOffer(orderRule, fgRule, discountType);
    Offer firstOffer = offers.get(0);
    OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
    qualCriteria.setQuantity(1);
    qualCriteria.setMatchRule(orderItemMatchRule);
    Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
    OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
    xref.setOffer(firstOffer);
    xref.setOfferItemCriteria(qualCriteria);
    criterias.add(xref);
    firstOffer.setQualifyingItemCriteriaXref(criterias);
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 4 with OfferItemCriteria

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

the class OfferDataItemProvider method createItemBasedOffer.

public List<Offer> createItemBasedOffer(String orderRule, String targetRule, OfferDiscountType discountType) {
    List<Offer> offers = createOrderBasedOffer(orderRule, discountType);
    offers.get(0).setType(OfferType.ORDER_ITEM);
    if (targetRule != null) {
        Offer offer = offers.get(0);
        OfferItemCriteria targetCriteria = new OfferItemCriteriaImpl();
        // targetCriteria.setQualifyingOffer(offers.get(0));
        targetCriteria.setQuantity(1);
        targetCriteria.setMatchRule(targetRule);
        OfferTargetCriteriaXref targetXref = new OfferTargetCriteriaXrefImpl();
        targetXref.setOffer(offer);
        targetXref.setOfferItemCriteria(targetCriteria);
        offer.setTargetItemCriteriaXref(Collections.singleton(targetXref));
    }
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) OfferTargetCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferTargetCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)

Example 5 with OfferItemCriteria

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

the class AbstractBaseProcessor method meetsItemQualifierSubtotal.

protected boolean meetsItemQualifierSubtotal(Offer offer, CandidatePromotionItems candidateItem) {
    Money qualifyingSubtotal = offer.getQualifyingItemSubTotal();
    if (!hasPositiveValue(qualifyingSubtotal)) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Offer " + offer.getName() + " does not have an item subtotal requirement.");
        }
        return true;
    }
    if (isEmpty(offer.getQualifyingItemCriteriaXref())) {
        if (OfferType.ORDER_ITEM.equals(offer.getType())) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Offer " + offer.getName() + " has a subtotal item requirement but no item qualification criteria.");
            }
            return false;
        } else {
            // Checking if targets meet subtotal for item offer with no item criteria.
            Money accumulatedTotal = null;
            for (PromotableOrderItem orderItem : candidateItem.getAllCandidateTargets()) {
                Money itemPrice = orderItem.getCurrentBasePrice().multiply(orderItem.getQuantity());
                accumulatedTotal = accumulatedTotal == null ? itemPrice : accumulatedTotal.add(itemPrice);
                if (accumulatedTotal.greaterThan(qualifyingSubtotal)) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Offer " + offer.getName() + " meets qualifying item subtotal.");
                    }
                    return true;
                }
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Offer " + offer.getName() + " does not meet qualifying item subtotal.");
        }
    } else {
        if (candidateItem.getCandidateQualifiersMap() != null) {
            Money accumulatedTotal = null;
            Set<PromotableOrderItem> usedItems = new HashSet<PromotableOrderItem>();
            for (OfferItemCriteria criteria : candidateItem.getCandidateQualifiersMap().keySet()) {
                List<PromotableOrderItem> promotableItems = candidateItem.getCandidateQualifiersMap().get(criteria);
                if (promotableItems != null) {
                    for (PromotableOrderItem item : promotableItems) {
                        if (!usedItems.contains(item)) {
                            usedItems.add(item);
                            Money itemPrice = item.getCurrentBasePrice().multiply(item.getQuantity());
                            accumulatedTotal = accumulatedTotal == null ? itemPrice : accumulatedTotal.add(itemPrice);
                            if (accumulatedTotal.greaterThan(qualifyingSubtotal)) {
                                if (LOG.isTraceEnabled()) {
                                    LOG.trace("Offer " + offer.getName() + " meets the item subtotal requirement.");
                                }
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Offer " + offer.getName() + " does not meet the item subtotal qualifications.");
    }
    return false;
}
Also used : Money(org.broadleafcommerce.common.money.Money) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) HashSet(java.util.HashSet)

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