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