use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class CandidateItemOfferTest method setUp.
@Override
protected void setUp() throws Exception {
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
CandidateItemOfferImpl candidate = new CandidateItemOfferImpl();
Category category1 = new CategoryImpl();
category1.setName("test1");
category1.setId(1L);
Product product1 = new ProductImpl();
Sku sku1 = new SkuImpl();
sku1.setName("test1");
sku1.setDiscountable(true);
sku1.setRetailPrice(new Money(19.99D));
product1.setDefaultSku(sku1);
CategoryProductXref xref1 = new CategoryProductXrefImpl();
xref1.setProduct(product1);
xref1.setCategory(category1);
category1.getAllProductXrefs().add(xref1);
Category category2 = new CategoryImpl();
category2.setName("test2");
category2.setId(2L);
Product product2 = new ProductImpl();
Sku sku2 = new SkuImpl();
sku2.setName("test2");
sku2.setDiscountable(true);
sku2.setRetailPrice(new Money(29.99D));
product2.setDefaultSku(sku2);
CategoryProductXref xref2 = new CategoryProductXrefImpl();
xref2.setProduct(product2);
xref2.setCategory(category2);
category2.getAllProductXrefs().add(xref2);
DiscreteOrderItemImpl orderItem1 = new DiscreteOrderItemImpl();
orderItem1.setCategory(category1);
orderItem1.setName("test1");
orderItem1.setOrderItemType(OrderItemType.DISCRETE);
orderItem1.setProduct(product1);
orderItem1.setQuantity(2);
orderItem1.setSku(sku1);
Order order = new OrderImpl();
orderItem1.setOrder(order);
promotableOrder = new PromotableOrderImpl(order, new PromotableItemFactoryImpl(), false);
offer = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))").get(0);
candidateOffer = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
promotableOrderItem = new PromotableOrderItemImpl(orderItem1, null, new PromotableItemFactoryImpl(), false);
OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl();
pdetail.setOrderItem(orderItem1);
pdetail.setQuantity(2);
priceDetail = new PromotableOrderItemPriceDetailImpl(promotableOrderItem, 2);
List<PromotableOrderItem> items = new ArrayList<PromotableOrderItem>();
items.add(promotableOrderItem);
promotableCandidate = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
OfferTargetCriteriaXref xref = offer.getTargetItemCriteriaXref().iterator().next();
promotableCandidate.getCandidateTargetsMap().put(xref.getOfferItemCriteria(), items);
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorTest method testFilterFulfillmentGroupLevelOffer.
public void testFilterFulfillmentGroupLevelOffer() {
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));
// test that the valid fg offer is included
// No item criteria, so each fulfillment group applies
assertTrue(qualifiedOffers.size() == 2 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
offers = dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the valid fg offer is included
// only 1 fulfillment group has qualifying items
assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
offers = dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75240", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"),MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the invalid fg offer is excluded - zipcode is wrong
assertTrue(qualifiedOffers.size() == 0);
qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
offers = dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"),MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
// test that the invalid fg offer is excluded - no qualifying items
assertTrue(qualifiedOffers.size() == 0);
verify();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorTest method testCouldOrderItemMeetOfferRequirement.
public void testCouldOrderItemMeetOfferRequirement() {
replay();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
List<Offer> offers = dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", 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 = fgProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().get(0));
// test that the valid fg offer is included
assertTrue(couldApply);
offers = dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", 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 = fgProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().get(0));
// test that the invalid fg offer is excluded
assertFalse(couldApply);
verify();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorTest method testCouldOfferApplyToOrder.
public void testCouldOfferApplyToOrder() throws Exception {
replay();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, null, null);
boolean couldApply = itemProcessor.couldOfferApplyToOrder(offers.get(0), order, order.getDiscountableOrderItems().get(0), order.getFulfillmentGroups().get(0));
// test that the valid order item offer is included
assertTrue(couldApply);
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()==0", OfferDiscountType.PERCENT_OFF, null, null);
couldApply = itemProcessor.couldOfferApplyToOrder(offers.get(0), order, order.getDiscountableOrderItems().get(0), order.getFulfillmentGroups().get(0));
// test that the invalid order item offer is excluded
assertFalse(couldApply);
verify();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorTest method testCouldOfferApplyToOrderItems.
public void testCouldOfferApplyToOrderItems() throws Exception {
replay();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([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 = itemProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
// test that the valid order item offer is included
// both cart items are valid for qualification and target
assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1 && candidates.getCandidateQualifiersMap().values().iterator().next().size() == 2 && candidates.isMatchedTarget() && candidates.getCandidateTargetsMap().size() == 1 && candidates.getCandidateTargetsMap().values().iterator().next().size() == 2);
offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
candidates = itemProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
// test that the invalid order item offer is excluded because there are no qualifying items
assertFalse(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
verify();
}
Aggregations