Search in sources :

Example 6 with PromotableFulfillmentGroup

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

Example 7 with PromotableFulfillmentGroup

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

the class OrderOfferProcessorImpl method synchronizeFulfillmentGroups.

protected void synchronizeFulfillmentGroups(PromotableOrder promotableOrder) {
    Order order = promotableOrder.getOrder();
    Map<Long, PromotableFulfillmentGroup> fgMap = buildPromotableFulfillmentGroupMap(promotableOrder);
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        synchronizeFulfillmentGroupAdjustments(fg, fgMap.get(fg.getId()));
    }
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)

Example 8 with PromotableFulfillmentGroup

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

the class FulfillmentGroupOfferProcessorTest method testApplyAllFulfillmentGroupOffers.

public void testApplyAllFulfillmentGroupOffers() {
    EasyMock.expect(offerServiceUtilitiesMock.orderMeetsQualifyingSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class), EasyMock.isA(HashMap.class))).andReturn(true).anyTimes();
    EasyMock.expect(offerServiceUtilitiesMock.orderMeetsSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class))).andReturn(true).anyTimes();
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<PromotableCandidateFulfillmentGroupOffer> qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
    List<Offer> offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
    fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
    boolean offerApplied = fgProcessor.applyAllFulfillmentGroupOffers(qualifiedOffers, order);
    assertTrue(offerApplied);
    order = dataProvider.createBasicPromotableOrder();
    qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
    offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
    offers.addAll(dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
    offers.get(1).setName("secondOffer");
    fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
    fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(1));
    offerApplied = fgProcessor.applyAllFulfillmentGroupOffers(qualifiedOffers, order);
    // the first offer applies to both fulfillment groups, but the second offer only applies to one of the fulfillment groups
    assertTrue(offerApplied);
    int fgAdjustmentCount = 0;
    for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
        fgAdjustmentCount += fg.getCandidateFulfillmentGroupAdjustments().size();
    }
    assertTrue(fgAdjustmentCount == 3);
    verify();
}
Also used : CandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) ArrayList(java.util.ArrayList) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Aggregations

PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)8 Money (org.broadleafcommerce.common.money.Money)3 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)3 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)3 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)3 ArrayList (java.util.ArrayList)2 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)2 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 HashMap (java.util.HashMap)1 List (java.util.List)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 NullComparator (org.apache.commons.collections.comparators.NullComparator)1 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)1 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 CandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer)1 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)1 FulfillmentGroupOfferPotential (org.broadleafcommerce.core.offer.service.discount.FulfillmentGroupOfferPotential)1 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1