Search in sources :

Example 11 with PromotableCandidateItemOffer

use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer 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)

Aggregations

PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)11 ArrayList (java.util.ArrayList)7 Offer (org.broadleafcommerce.core.offer.domain.Offer)6 Money (org.broadleafcommerce.common.money.Money)4 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)4 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)4 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)4 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)3 PromotableOrderItemPriceDetail (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)2 Order (org.broadleafcommerce.core.order.domain.Order)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)1 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)1 OfferTargetCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)1 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)1 PromotionDiscount (org.broadleafcommerce.core.offer.service.discount.PromotionDiscount)1 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)1 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1