use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class OrderOfferProcessorTest method testFilterOffers.
public void testFilterOffers() throws Exception {
replay();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
List<Offer> offers = dataProvider.createCustomerBasedOffer("customer.registered==true", dataProvider.yesterday(), dataProvider.yesterday(), OfferDiscountType.PERCENT_OFF);
orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
// confirm out-of-date orders are filtered out
assertTrue(offers.size() == 0);
offers = dataProvider.createCustomerBasedOffer("customer.registered==true", dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF);
orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
// confirm valid customer offer is retained
assertTrue(offers.size() == 1);
offers = dataProvider.createCustomerBasedOffer("customer.registered==false", dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF);
orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
// confirm invalid customer offer is culled
assertTrue(offers.size() == 0);
verify();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder 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();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder 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.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class OrderOfferProcessorTest method testCouldOrderItemMeetOfferRequirement.
public void testCouldOrderItemMeetOfferRequirement() 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))");
OfferQualifyingCriteriaXref xref = offers.get(0).getQualifyingItemCriteriaXref().iterator().next();
boolean couldApply = orderProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().get(0));
// test that the valid order offer is included
assertTrue(couldApply);
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))");
xref = offers.get(0).getQualifyingItemCriteriaXref().iterator().next();
couldApply = orderProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().get(0));
// test that the invalid order offer is excluded
assertFalse(couldApply);
verify();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class OrderOfferProcessorImpl method synchronizeOrderItems.
protected void synchronizeOrderItems(PromotableOrder promotableOrder) {
Order order = promotableOrder.getOrder();
Map<OrderItem, PromotableOrderItem> promotableItemMap = offerServiceUtilities.buildPromotableItemMap(promotableOrder);
List<OrderItem> orderItemList = offerServiceUtilities.buildOrderItemList(order);
for (OrderItem orderItem : orderItemList) {
PromotableOrderItem promotableItem = promotableItemMap.get(orderItem);
if (promotableItem == null) {
continue;
}
synchronizeItemPriceDetails(orderItem, promotableItem);
synchronizeItemQualifiers(orderItem, promotableItem);
}
}
Aggregations