Search in sources :

Example 21 with PromotableOrder

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

the class ItemOfferProcessorTest method testApplyItemQualifiersAndTargets.

public void testApplyItemQualifiersAndTargets() throws Exception {
    replay();
    List<PromotableCandidateItemOffer> qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    Offer offer1 = 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);
    offer1.setId(1L);
    Offer offer2 = 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);
    offer2.setId(2L);
    OfferTargetCriteriaXref targetXref = offer2.getTargetItemCriteriaXref().iterator().next();
    targetXref.getOfferItemCriteria().setQuantity(4);
    offer2.getQualifyingItemCriteriaXref().clear();
    offer2.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
    Offer offer3 = 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);
    PromotableOrder promotableOrder = dataProvider.createBasicPromotableOrder();
    itemProcessor.filterItemLevelOffer(promotableOrder, qualifiedOffers, offer1);
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offer1) && qualifiedOffers.get(0).getCandidateQualifiersMap().size() == 1);
    itemProcessor.filterItemLevelOffer(promotableOrder, qualifiedOffers, offer2);
    assertTrue(qualifiedOffers.size() == 2 && qualifiedOffers.get(1).getOffer().equals(offer2) && qualifiedOffers.get(1).getCandidateQualifiersMap().size() == 0);
    itemProcessor.filterItemLevelOffer(promotableOrder, qualifiedOffers, offer3);
    assertTrue(qualifiedOffers.size() == 3 && qualifiedOffers.get(2).getOffer().equals(offer3) && qualifiedOffers.get(2).getCandidateQualifiersMap().size() == 1);
    // Try with just the second offer.   Expect to get 4 targets based on the offer having no qualifiers required
    // and targeting category test1 or test2 and that the offer requires 4 target criteria.
    Order order = dataProvider.createBasicOrder();
    List<Offer> offerList = new ArrayList<Offer>();
    offerList.add(offer2);
    offerService.applyAndSaveOffersToOrder(offerList, order);
    assertTrue(checkOrderItemOfferAppliedQuantity(order, offer2) == 4);
    assertTrue(countPriceDetails(order) == 3);
    // Now try with both offers.   Since the targets can be reused, we expect to have 4 targets on offer2
    // and 1 target on offer1
    order = dataProvider.createBasicOrder();
    // add in second offer (which happens to be offer1)
    offerList.add(offer1);
    offerService.applyAndSaveOffersToOrder(offerList, order);
    assertTrue(checkOrderItemOfferAppliedQuantity(order, offer2) == 4);
    assertTrue(countPriceDetails(order) == 3);
    // All three offers - offer 3 is now higher priority so the best offer (offer 2) won't be applied
    order = dataProvider.createBasicOrder();
    // add in second offer (which happens to be offer1)
    offerList.add(offer3);
    offer3.setPriority(-1);
    offerService.applyAndSaveOffersToOrder(offerList, order);
    assertTrue(checkOrderItemOfferAppliedQuantity(order, offer3) == 2);
    assertTrue(countPriceDetails(order) == 4);
    verify();
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) ArrayList(java.util.ArrayList) OfferTargetCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Example 22 with PromotableOrder

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

the class ItemOfferProcessorTest method testFilterItemLevelOffer.

public void testFilterItemLevelOffer() throws Exception {
    replay();
    List<PromotableCandidateItemOffer> qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, null, null);
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order item offer is included - legacy format - no qualifier
    // since there's no qualifier, both items can apply
    // This line is commented out because we are no longer creating legacy offers.
    // assertTrue(qualifiedOffers.size() == 2 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(1).getOffer().equals(offers.get(0)));
    qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    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))");
    itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order item offer is included
    // there is a qualifier and the item qualifying criteria requires only 1, therefore there will be only one qualifier in the qualifiers map
    // we don't know the targets yet, so there's only one CandidateItemOffer for now
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(0).getCandidateQualifiersMap().size() == 1);
    // Add a subtotal requirement that will be met by the item offer.
    qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    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))");
    offers.get(0).setQualifyingItemSubTotal(new Money(1));
    itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order item offer is included
    // there is a qualifier and the item qualifying criteria requires only 1, therefore there will be only one qualifier in the qualifiers map
    // we don't know the targets yet, so there's only one CandidateItemOffer for now
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)) && qualifiedOffers.get(0).getCandidateQualifiersMap().size() == 1);
    // Add a subtotal requirement that will not be met by the item offer.
    qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    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))");
    offers.get(0).setQualifyingItemSubTotal(new Money(99999));
    itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
    // Since the item qualification subTotal is not met, the qualified offer size should
    // be zero.
    assertTrue(qualifiedOffers.size() == 0);
    qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
    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))");
    itemProcessor.filterItemLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the invalid order item offer is excluded
    assertTrue(qualifiedOffers.size() == 0);
    verify();
}
Also used : Money(org.broadleafcommerce.common.money.Money) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Example 23 with PromotableOrder

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

the class OrderOfferProcessorTest method testCouldOfferApplyToOrder.

public void testCouldOfferApplyToOrder() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createOrderBasedOffer("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF);
    boolean couldApply = orderProcessor.couldOfferApplyToOrder(offers.get(0), order, order.getDiscountableOrderItems().get(0), order.getFulfillmentGroups().get(0));
    // test that the valid order offer is included
    assertTrue(couldApply);
    offers = dataProvider.createOrderBasedOffer("order.subTotal.getAmount()==0", OfferDiscountType.PERCENT_OFF);
    couldApply = orderProcessor.couldOfferApplyToOrder(offers.get(0), order, order.getDiscountableOrderItems().get(0), order.getFulfillmentGroups().get(0));
    // test that the invalid order offer is excluded
    assertFalse(couldApply);
    verify();
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Example 24 with PromotableOrder

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

the class OrderOfferProcessorTest method testQualifyingQuantity.

public void testQualifyingQuantity() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createOrderBasedOffer("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF);
    Offer firstOffer = offers.get(0);
    OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
    int originalQuantityOnOrder = 5;
    qualCriteria.setQuantity(originalQuantityOnOrder + 1);
    qualCriteria.setMatchRule("([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
    OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
    xref.setOffer(firstOffer);
    xref.setOfferItemCriteria(qualCriteria);
    criterias.add(xref);
    firstOffer.setQualifyingItemCriteriaXref(criterias);
    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 not included
    assertTrue(!candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    int quantity = orderItems.get(0).getOrderItem().getQuantity();
    orderItems.get(0).getOrderItem().setQuantity(quantity + 1);
    candidates = orderProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the valid order offer is included
    assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    verify();
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 25 with PromotableOrder

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

the class OrderItemTest method setUp.

@Override
protected void setUp() throws Exception {
    PromotableOrder promotableOrder = new PromotableOrderImpl(new OrderImpl(), new PromotableItemFactoryImpl(), false);
    DiscreteOrderItemImpl discreteOrderItem1 = new DiscreteOrderItemImpl();
    discreteOrderItem1.setName("test1");
    discreteOrderItem1.setOrderItemType(OrderItemType.DISCRETE);
    discreteOrderItem1.setQuantity(2);
    discreteOrderItem1.setRetailPrice(new Money(19.99D));
    OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl();
    pdetail.setOrderItem(discreteOrderItem1);
    pdetail.setQuantity(2);
    PromotableOrderItem orderItem1 = new PromotableOrderItemImpl(discreteOrderItem1, null, new PromotableItemFactoryImpl(), false);
    priceDetail1 = new PromotableOrderItemPriceDetailImpl(orderItem1, 2);
    OfferDataItemProvider dataProvider = new OfferDataItemProvider();
    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);
}
Also used : PromotableOrderItemImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) Money(org.broadleafcommerce.common.money.Money) PromotableItemFactoryImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableItemFactoryImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) OfferDataItemProvider(org.broadleafcommerce.core.offer.service.OfferDataItemProvider) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl)

Aggregations

PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)25 Offer (org.broadleafcommerce.core.offer.domain.Offer)20 ArrayList (java.util.ArrayList)13 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)11 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)9 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)8 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)8 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)8 Order (org.broadleafcommerce.core.order.domain.Order)7 CandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer)6 OfferQualifyingCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)4 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)4 Money (org.broadleafcommerce.common.money.Money)3 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)3 PromotableItemFactoryImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableItemFactoryImpl)3 PromotableOrderImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl)3 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)2 OfferDataItemProvider (org.broadleafcommerce.core.offer.service.OfferDataItemProvider)2 PromotableCandidateItemOfferImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl)2 PromotableOrderItemImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemImpl)2