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());
}
}
}
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()));
}
}
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();
}
Aggregations