Search in sources :

Example 1 with OfferQualifyingCriteriaXrefImpl

use of org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferDataItemProvider method createItemBasedOfferWithItemCriteria.

public List<Offer> createItemBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String qualRule, String targetRule) {
    List<Offer> offers = createItemBasedOffer(orderRule, targetRule, discountType);
    if (qualRule != null) {
        Offer firstOffer = offers.get(0);
        OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
        // qualCriteria.setQualifyingOffer(offers.get(0));
        qualCriteria.setQuantity(1);
        qualCriteria.setMatchRule(qualRule);
        Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
        OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
        xref.setOffer(firstOffer);
        xref.setOfferItemCriteria(qualCriteria);
        criterias.add(xref);
        firstOffer.setQualifyingItemCriteriaXref(criterias);
    }
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 2 with OfferQualifyingCriteriaXrefImpl

use of org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferDataItemProvider method createOrderBasedOfferWithItemCriteria.

public List<Offer> createOrderBasedOfferWithItemCriteria(String orderRule, OfferDiscountType discountType, String orderItemMatchRule) {
    List<Offer> offers = createOrderBasedOffer(orderRule, discountType);
    Offer firstOffer = offers.get(0);
    OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
    // qualCriteria.setQualifyingOffer(offers.get(0));
    qualCriteria.setQuantity(1);
    qualCriteria.setMatchRule(orderItemMatchRule);
    Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
    OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
    xref.setOffer(firstOffer);
    xref.setOfferItemCriteria(qualCriteria);
    criterias.add(xref);
    firstOffer.setQualifyingItemCriteriaXref(criterias);
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 3 with OfferQualifyingCriteriaXrefImpl

use of org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferDataItemProvider method createFGBasedOfferWithItemCriteria.

public List<Offer> createFGBasedOfferWithItemCriteria(String orderRule, String fgRule, OfferDiscountType discountType, String orderItemMatchRule) {
    List<Offer> offers = createFGBasedOffer(orderRule, fgRule, discountType);
    Offer firstOffer = offers.get(0);
    OfferItemCriteria qualCriteria = new OfferItemCriteriaImpl();
    qualCriteria.setQuantity(1);
    qualCriteria.setMatchRule(orderItemMatchRule);
    Set<OfferQualifyingCriteriaXref> criterias = new HashSet<OfferQualifyingCriteriaXref>();
    OfferQualifyingCriteriaXref xref = new OfferQualifyingCriteriaXrefImpl();
    xref.setOffer(firstOffer);
    xref.setOfferItemCriteria(qualCriteria);
    criterias.add(xref);
    firstOffer.setQualifyingItemCriteriaXref(criterias);
    return offers;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref) HashSet(java.util.HashSet)

Example 4 with OfferQualifyingCriteriaXrefImpl

use of org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl in project BroadleafCommerce by BroadleafCommerce.

the class CreateOfferUtility method createOffer.

public Offer createOffer(String offerName, OfferType offerType, OfferDiscountType discountType, double value, String orderRule, boolean stackable, boolean combinable, int priority, String qualifierRule) {
    Offer offer = offerDao.create();
    offer.setName(offerName);
    offer.setStartDate(SystemTime.asDate());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1);
    offer.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 2);
    offer.setEndDate(calendar.getTime());
    offer.setType(offerType);
    offer.setDiscountType(discountType);
    offer.setValue(BigDecimal.valueOf(value));
    if (stackable) {
        offer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER_TARGET);
    }
    OfferItemCriteria oic = new OfferItemCriteriaImpl();
    oic.setQuantity(1);
    oic.setMatchRule(orderRule);
    OfferTargetCriteriaXref targetXref = new OfferTargetCriteriaXrefImpl();
    targetXref.setOffer(offer);
    targetXref.setOfferItemCriteria(oic);
    offer.setTargetItemCriteriaXref(Collections.singleton(targetXref));
    offer.setCombinableWithOtherOffers(combinable);
    if (qualifierRule != null) {
        OfferItemCriteria qoic = new OfferItemCriteriaImpl();
        qoic.setQuantity(1);
        qoic.setMatchRule(qualifierRule);
        OfferQualifyingCriteriaXref qualifyingXref = new OfferQualifyingCriteriaXrefImpl();
        qualifyingXref.setOffer(offer);
        qualifyingXref.setOfferItemCriteria(qoic);
        offer.setQualifyingItemCriteriaXref(Collections.singleton(qualifyingXref));
        offer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.QUALIFIER_TARGET);
    }
    offer.setPriority(priority);
    offer = offerService.save(offer);
    offer.setMaxUsesPerOrder(50);
    return offer;
}
Also used : OfferItemCriteriaImpl(org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl) OfferTargetCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl) Offer(org.broadleafcommerce.core.offer.domain.Offer) Calendar(java.util.Calendar) OfferItemCriteria(org.broadleafcommerce.core.offer.domain.OfferItemCriteria) OfferQualifyingCriteriaXrefImpl(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl) OfferTargetCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)

Example 5 with OfferQualifyingCriteriaXrefImpl

use of org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl 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

Offer (org.broadleafcommerce.core.offer.domain.Offer)5 OfferItemCriteria (org.broadleafcommerce.core.offer.domain.OfferItemCriteria)5 OfferItemCriteriaImpl (org.broadleafcommerce.core.offer.domain.OfferItemCriteriaImpl)5 OfferQualifyingCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)5 OfferQualifyingCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXrefImpl)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 OfferTargetCriteriaXref (org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXref)1 OfferTargetCriteriaXrefImpl (org.broadleafcommerce.core.offer.domain.OfferTargetCriteriaXrefImpl)1 CandidatePromotionItems (org.broadleafcommerce.core.offer.service.discount.CandidatePromotionItems)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)1 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)1