Search in sources :

Example 6 with PromotableOrderItem

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem 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 PromotableOrderItem

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method filterOrderLevelOffer.

@Override
public void filterOrderLevelOffer(PromotableOrder promotableOrder, List<PromotableCandidateOrderOffer> qualifiedOrderOffers, Offer offer) {
    if (offer.getDiscountType().getType().equals(OfferDiscountType.FIX_PRICE.getType())) {
        LOG.warn("Offers of type ORDER may not have a discount type of FIX_PRICE. Ignoring order offer (name=" + offer.getName() + ")");
        return;
    }
    boolean orderLevelQualification = false;
    // Order Qualification
    orderQualification: {
        if (couldOfferApplyToOrder(offer, promotableOrder)) {
            orderLevelQualification = true;
            break orderQualification;
        }
        for (PromotableOrderItem orderItem : promotableOrder.getDiscountableOrderItems(offer.getApplyDiscountToSalePrice())) {
            if (couldOfferApplyToOrder(offer, promotableOrder, orderItem)) {
                orderLevelQualification = true;
                break orderQualification;
            }
        }
        for (PromotableFulfillmentGroup fulfillmentGroup : promotableOrder.getFulfillmentGroups()) {
            if (couldOfferApplyToOrder(offer, promotableOrder, fulfillmentGroup)) {
                orderLevelQualification = true;
                break orderQualification;
            }
        }
    }
    // Item Qualification - new for 1.5!
    if (orderLevelQualification) {
        CandidatePromotionItems candidates = couldOfferApplyToOrderItems(offer, promotableOrder.getDiscountableOrderItems(offer.getApplyDiscountToSalePrice()));
        if (candidates.isMatchedQualifier()) {
            PromotableCandidateOrderOffer candidateOffer = createCandidateOrderOffer(promotableOrder, qualifiedOrderOffers, offer);
            candidateOffer.getCandidateQualifiersMap().putAll(candidates.getCandidateQualifiersMap());
        }
    }
}
Also used : CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 8 with PromotableOrderItem

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method synchronizeOrderItems.

protected void synchronizeOrderItems(PromotableOrder promotableOrder) {
    Order order = promotableOrder.getOrder();
    Map<OrderItem, PromotableOrderItem> promotableItemMap = offerServiceUtilities.buildPromotableItemMap(promotableOrder);
    List<OrderItem> orderItemList = offerServiceUtilities.buildOrderItemList(order);
    for (OrderItem orderItem : orderItemList) {
        PromotableOrderItem promotableItem = promotableItemMap.get(orderItem);
        if (promotableItem == null) {
            continue;
        }
        synchronizeItemPriceDetails(orderItem, promotableItem);
        synchronizeItemQualifiers(orderItem, promotableItem);
    }
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 9 with PromotableOrderItem

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method checkForItemRequirements.

protected void checkForItemRequirements(Offer offer, CandidatePromotionItems candidates, OfferItemCriteria criteria, List<PromotableOrderItem> promotableOrderItems, boolean isQualifier) {
    boolean matchFound = false;
    int criteriaQuantity = criteria.getQuantity();
    int matchedQuantity = 0;
    if (criteriaQuantity > 0) {
        // for this promotion.
        for (PromotableOrderItem item : promotableOrderItems) {
            if (couldOrderItemMeetOfferRequirement(criteria, item)) {
                if (isQualifier) {
                    candidates.addQualifier(criteria, item);
                } else {
                    candidates.addTarget(criteria, item);
                    addChildOrderItemsToCandidates(offer, candidates, criteria, promotableOrderItems, item);
                }
                matchedQuantity += item.getQuantity();
            }
        }
        matchFound = (matchedQuantity >= criteriaQuantity);
    }
    if (isQualifier) {
        candidates.setMatchedQualifier(matchFound);
    } else {
        candidates.setMatchedTarget(matchFound);
    }
}
Also used : PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 10 with PromotableOrderItem

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem in project BroadleafCommerce by BroadleafCommerce.

the class AbstractBaseProcessor method addChildOrderItemsToCandidates.

protected void addChildOrderItemsToCandidates(Offer offer, CandidatePromotionItems candidates, OfferItemCriteria criteria, List<PromotableOrderItem> promotableOrderItems, PromotableOrderItem item) {
    if (offer.getApplyToChildItems()) {
        final List<OrderItem> childItems = item.getOrderItem().getChildOrderItems();
        if (CollectionUtils.isEmpty(childItems)) {
            return;
        }
        List<PromotableOrderItem> filteredItems = new ArrayList<>();
        filteredItems.addAll(promotableOrderItems);
        CollectionUtils.filter(filteredItems, new TypedPredicate<PromotableOrderItem>() {

            @Override
            public boolean eval(PromotableOrderItem promotableOrderItem) {
                return childItems.contains(promotableOrderItem.getOrderItem());
            }
        });
        for (PromotableOrderItem promotableOrderItem : filteredItems) {
            candidates.addTarget(criteria, promotableOrderItem);
        }
    }
}
Also used : PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ArrayList(java.util.ArrayList) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Aggregations

PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)19 ArrayList (java.util.ArrayList)8 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)7 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)7 Money (org.broadleafcommerce.common.money.Money)6 Offer (org.broadleafcommerce.core.offer.domain.Offer)6 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)6 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)6 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)5 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)5 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)3 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)3 HashSet (java.util.HashSet)2 List (java.util.List)2 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)2 OfferDataItemProvider (org.broadleafcommerce.core.offer.service.OfferDataItemProvider)2 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 PromotableItemFactoryImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableItemFactoryImpl)2 PromotableOrderImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl)2