Search in sources :

Example 1 with CandidatePromotionItems

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

the class ItemOfferProcessorTest method testCouldOfferApplyToOrderItems.

public void testCouldOfferApplyToOrderItems() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    List<PromotableOrderItem> orderItems = new ArrayList<PromotableOrderItem>();
    for (PromotableOrderItem orderItem : order.getDiscountableOrderItems()) {
        orderItems.add(orderItem);
    }
    CandidatePromotionItems candidates = itemProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the valid order item offer is included
    // both cart items are valid for qualification and target
    assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1 && candidates.getCandidateQualifiersMap().values().iterator().next().size() == 2 && candidates.isMatchedTarget() && candidates.getCandidateTargetsMap().size() == 1 && candidates.getCandidateTargetsMap().values().iterator().next().size() == 2);
    offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    candidates = itemProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the invalid order item offer is excluded because there are no qualifying items
    assertFalse(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    verify();
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 2 with CandidatePromotionItems

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

the class OrderOfferProcessorTest method testCouldOfferApplyToOrderItems.

public void testCouldOfferApplyToOrderItems() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    List<PromotableOrderItem> orderItems = new ArrayList<PromotableOrderItem>();
    for (PromotableOrderItem orderItem : order.getDiscountableOrderItems()) {
        orderItems.add(orderItem);
    }
    CandidatePromotionItems candidates = orderProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the valid order offer is included
    assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    candidates = orderProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the invalid order offer is excluded because there are no qualifying items
    assertFalse(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    verify();
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 3 with CandidatePromotionItems

use of org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems 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 4 with CandidatePromotionItems

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

the class FulfillmentGroupOfferProcessorImpl method filterFulfillmentGroupLevelOffer.

@Override
public void filterFulfillmentGroupLevelOffer(PromotableOrder order, List<PromotableCandidateFulfillmentGroupOffer> qualifiedFGOffers, Offer offer) {
    for (PromotableFulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        boolean fgLevelQualification = false;
        fgQualification: {
            // handle legacy fields in addition to the 1.5 order rule field
            if (couldOfferApplyToOrder(offer, order, fulfillmentGroup)) {
                fgLevelQualification = true;
                break fgQualification;
            }
            for (PromotableOrderItem discreteOrderItem : order.getAllOrderItems()) {
                if (couldOfferApplyToOrder(offer, order, discreteOrderItem, fulfillmentGroup)) {
                    fgLevelQualification = true;
                    break fgQualification;
                }
            }
        }
        if (fgLevelQualification) {
            fgLevelQualification = false;
            // handle 1.5 FG field
            if (couldOfferApplyToFulfillmentGroup(offer, fulfillmentGroup)) {
                fgLevelQualification = true;
            }
        }
        // Item Qualification - new for 1.5!
        if (fgLevelQualification) {
            CandidatePromotionItems candidates = couldOfferApplyToOrderItems(offer, fulfillmentGroup.getDiscountableOrderItems());
            // on all the items in the order across all fulfillment groups (not the default behavior)
            if (!candidates.isMatchedQualifier() && getQualifyGroupAcrossAllOrderItems(fulfillmentGroup)) {
                candidates = couldOfferApplyToOrderItems(offer, order.getAllOrderItems());
            }
            if (candidates.isMatchedQualifier()) {
                PromotableCandidateFulfillmentGroupOffer candidateOffer = createCandidateFulfillmentGroupOffer(offer, qualifiedFGOffers, fulfillmentGroup);
                candidateOffer.getCandidateQualifiersMap().putAll(candidates.getCandidateQualifiersMap());
            }
        }
    }
}
Also used : CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 5 with CandidatePromotionItems

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

the class ItemOfferProcessorImpl method filterItemLevelOffer.

/* (non-Javadoc)
     * @see org.broadleafcommerce.core.offer.service.processor.ItemOfferProcessor#filterItemLevelOffer(org.broadleafcommerce.core.order.domain.Order, java.util.List, java.util.List, org.broadleafcommerce.core.offer.domain.Offer)
     */
@Override
public void filterItemLevelOffer(PromotableOrder order, List<PromotableCandidateItemOffer> qualifiedItemOffers, Offer offer) {
    boolean isNewFormat = CollectionUtils.isNotEmpty(offer.getQualifyingItemCriteriaXref()) || CollectionUtils.isNotEmpty(offer.getTargetItemCriteriaXref());
    boolean itemLevelQualification = false;
    boolean offerCreated = false;
    for (PromotableOrderItem promotableOrderItem : order.getDiscountableOrderItems()) {
        if (couldOfferApplyToOrder(offer, order, promotableOrderItem)) {
            if (!isNewFormat) {
                // support legacy offers
                PromotableCandidateItemOffer candidate = createCandidateItemOffer(qualifiedItemOffers, offer, order);
                if (!candidate.getLegacyCandidateTargets().contains(promotableOrderItem)) {
                    candidate.getLegacyCandidateTargets().add(promotableOrderItem);
                }
                offerCreated = true;
                continue;
            }
            itemLevelQualification = true;
            break;
        }
        for (PromotableFulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
            if (couldOfferApplyToOrder(offer, order, promotableOrderItem, fulfillmentGroup)) {
                if (!isNewFormat) {
                    // support legacy offers
                    PromotableCandidateItemOffer candidate = createCandidateItemOffer(qualifiedItemOffers, offer, order);
                    if (!candidate.getLegacyCandidateTargets().contains(promotableOrderItem)) {
                        candidate.getLegacyCandidateTargets().add(promotableOrderItem);
                    }
                    offerCreated = true;
                    continue;
                }
                itemLevelQualification = true;
                break;
            }
        }
    }
    // Item Qualification - new for 1.5!
    if (itemLevelQualification && !offerCreated) {
        CandidatePromotionItems candidates = couldOfferApplyToOrderItems(offer, order.getDiscountableOrderItems(offer.getApplyDiscountToSalePrice()));
        PromotableCandidateItemOffer candidateOffer = null;
        if (candidates.isMatchedQualifier()) {
            // we don't know the final target yet, so put null for the order item for now
            candidateOffer = createCandidateItemOffer(qualifiedItemOffers, offer, order);
            candidateOffer.getCandidateQualifiersMap().putAll(candidates.getCandidateQualifiersMap());
        }
        if (candidates.isMatchedTarget() && candidates.isMatchedQualifier()) {
            if (candidateOffer == null) {
                // we don't know the final target yet, so put null for the order item for now
                candidateOffer = createCandidateItemOffer(qualifiedItemOffers, offer, order);
            }
            candidateOffer.getCandidateTargetsMap().putAll(candidates.getCandidateTargetsMap());
        }
    }
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Aggregations

CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)7 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 ArrayList (java.util.ArrayList)4 Offer (org.broadleafcommerce.core.offer.domain.Offer)4 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)4 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)3 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)3 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)2 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 HashSet (java.util.HashSet)1 CandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer)1 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)1 OfferItemCriteriaImpl (org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl)1 OfferQualifyingCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)1 OfferQualifyingCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl)1