Search in sources :

Example 6 with CandidatePromotionItems

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

the class FulfillmentGroupOfferProcessorTest method testCouldOfferApplyToOrderItems.

public void testCouldOfferApplyToOrderItems() {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<PromotableOrderItem> orderItems = new ArrayList<PromotableOrderItem>();
    for (PromotableOrderItem orderItem : order.getDiscountableOrderItems()) {
        orderItems.add(orderItem);
    }
    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))");
    CandidatePromotionItems candidates = fgProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the valid fg offer is included
    assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    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))");
    candidates = fgProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the invalid fg offer is excluded because there are no qualifying items
    assertFalse(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    verify();
}
Also used : CandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidatePromotionItems(org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

Example 7 with CandidatePromotionItems

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

Aggregations

CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)7 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 ArrayList (java.util.ArrayList)4 Offer (org.broadleafcommerce.core.offer.domain.Offer)4 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)4 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)3 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)3 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)2 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)2 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)2 HashSet (java.util.HashSet)1 CandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer)1 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)1 OfferItemCriteriaImpl (org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl)1 OfferQualifyingCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)1 OfferQualifyingCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl)1