Search in sources :

Example 1 with PromotableCandidateOrderOffer

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

the class OrderOfferProcessorTest method testFilterOrderLevelOffer.

public void testFilterOrderLevelOffer() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<PromotableCandidateOrderOffer> qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    List<Offer> offers = dataProvider.createOrderBasedOffer("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF);
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order offer is included
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
    qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    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))");
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order offer is included
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
    qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([5,6] contains discreteOrderItem.category.id.intValue())");
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the invalid order offer is excluded
    assertTrue(qualifiedOffers.size() == 0);
    verify();
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Example 2 with PromotableCandidateOrderOffer

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

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

the class ItemOfferProcessorImpl method applyAndCompareOrderAndItemOffers.

@Override
@SuppressWarnings("unchecked")
public void applyAndCompareOrderAndItemOffers(PromotableOrder order, List<PromotableCandidateOrderOffer> qualifiedOrderOffers, List<PromotableCandidateItemOffer> qualifiedItemOffers) {
    if (!qualifiedItemOffers.isEmpty()) {
        calculatePotentialSavings(qualifiedItemOffers, order);
        // the actual application of those offers. Thus the uses for each item offer needs to be reset
        for (PromotableCandidateItemOffer itemOffer : qualifiedItemOffers) {
            itemOffer.resetUses();
        }
        // Sort order item offers by priority and potential total discount
        Collections.sort(qualifiedItemOffers, ItemOfferComparator.INSTANCE);
        if (qualifiedItemOffers.size() > 1) {
            qualifiedItemOffers = determineBestPermutation(qualifiedItemOffers, order);
        }
        applyAllItemOffers(qualifiedItemOffers, order);
    }
    chooseSaleOrRetailAdjustments(order);
    if (extensionManager != null) {
        extensionManager.chooseSaleOrRetailAdjustments(order);
    }
    order.setOrderSubTotalToPriceWithAdjustments();
    if (!qualifiedOrderOffers.isEmpty()) {
        // Sort order offers by priority and discount
        Collections.sort(qualifiedOrderOffers, OrderOfferComparator.INSTANCE);
        applyAllOrderOffers(qualifiedOrderOffers, order);
    }
    order.setOrderSubTotalToPriceWithAdjustments();
    // pull it out and reapply.
    if (!qualifiedOrderOffers.isEmpty() && !qualifiedItemOffers.isEmpty()) {
        List<PromotableCandidateOrderOffer> finalQualifiedOrderOffers = new ArrayList<PromotableCandidateOrderOffer>();
        order.removeAllCandidateOrderOfferAdjustments();
        for (PromotableCandidateOrderOffer candidateOrderOffer : qualifiedOrderOffers) {
            /*
                 * Note - there is an edge case possibility where this logic would miss an order promotion
                 * that had a subtotal requirement that was missed because of item deductions, but without
                 * the item deductions, the order promotion would have been included and ended up giving the 
                 * customer a better deal than the item deductions.
                 */
            if (couldOfferApplyToOrder(candidateOrderOffer.getOffer(), order)) {
                finalQualifiedOrderOffers.add(candidateOrderOffer);
            }
        }
        // Sort order offers by priority and discount
        Collections.sort(finalQualifiedOrderOffers, OrderOfferComparator.INSTANCE);
        if (!finalQualifiedOrderOffers.isEmpty()) {
            applyAllOrderOffers(finalQualifiedOrderOffers, order);
            order.setOrderSubTotalToPriceWithAdjustments();
        }
    }
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) ArrayList(java.util.ArrayList)

Example 4 with PromotableCandidateOrderOffer

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

the class OrderOfferProcessorImpl method createCandidateOrderOffer.

protected PromotableCandidateOrderOffer createCandidateOrderOffer(PromotableOrder promotableOrder, List<PromotableCandidateOrderOffer> qualifiedOrderOffers, Offer offer) {
    PromotableCandidateOrderOffer promotableCandidateOrderOffer = promotableItemFactory.createPromotableCandidateOrderOffer(promotableOrder, offer);
    qualifiedOrderOffers.add(promotableCandidateOrderOffer);
    return promotableCandidateOrderOffer;
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)

Example 5 with PromotableCandidateOrderOffer

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

the class OrderOfferProcessorImpl method removeTrailingNotCombinableOrderOffers.

@Override
public List<PromotableCandidateOrderOffer> removeTrailingNotCombinableOrderOffers(List<PromotableCandidateOrderOffer> candidateOffers) {
    List<PromotableCandidateOrderOffer> remainingCandidateOffers = new ArrayList<PromotableCandidateOrderOffer>();
    int offerCount = 0;
    for (PromotableCandidateOrderOffer candidateOffer : candidateOffers) {
        if (offerCount == 0) {
            remainingCandidateOffers.add(candidateOffer);
        } else {
            if (candidateOffer.getOffer().isCombinableWithOtherOffers() && !candidateOffer.getOffer().isTotalitarianOffer()) {
                remainingCandidateOffers.add(candidateOffer);
            }
        }
        offerCount++;
    }
    return remainingCandidateOffers;
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) ArrayList(java.util.ArrayList)

Aggregations

PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)7 ArrayList (java.util.ArrayList)4 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)2 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)1 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)1 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)1 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)1 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)1 Transactional (org.springframework.transaction.annotation.Transactional)1