Search in sources :

Example 6 with PromotableOrder

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

the class OrderOfferProcessorTest method testFilterOffers.

public void testFilterOffers() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createCustomerBasedOffer("customer.registered==true", dataProvider.yesterday(), dataProvider.yesterday(), OfferDiscountType.PERCENT_OFF);
    orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
    // confirm out-of-date orders are filtered out
    assertTrue(offers.size() == 0);
    offers = dataProvider.createCustomerBasedOffer("customer.registered==true", dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF);
    orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
    // confirm valid customer offer is retained
    assertTrue(offers.size() == 1);
    offers = dataProvider.createCustomerBasedOffer("customer.registered==false", dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF);
    orderProcessor.filterOffers(offers, order.getOrder().getCustomer());
    // confirm invalid customer offer is culled
    assertTrue(offers.size() == 0);
    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 7 with PromotableOrder

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

the class OrderOfferProcessorTest method testCouldOfferApplyToOrderItems.

public void testCouldOfferApplyToOrderItems() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([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 = orderProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the valid order offer is included
    assertTrue(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test5\"), MVEL.eval(\"toUpperCase()\",\"test6\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    candidates = orderProcessor.couldOfferApplyToOrderItems(offers.get(0), orderItems);
    // test that the invalid order offer is excluded because there are no qualifying items
    assertFalse(candidates.isMatchedQualifier() && candidates.getCandidateQualifiersMap().size() == 1);
    verify();
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) 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 8 with PromotableOrder

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

the class OrderOfferProcessorTest method testFilterOrderLevelOffer.

public void testFilterOrderLevelOffer() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<PromotableCandidateOrderOffer> qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    List<Offer> offers = dataProvider.createOrderBasedOffer("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF);
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order offer is included
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
    qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))");
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the valid order offer is included
    assertTrue(qualifiedOffers.size() == 1 && qualifiedOffers.get(0).getOffer().equals(offers.get(0)));
    qualifiedOffers = new ArrayList<PromotableCandidateOrderOffer>();
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([5,6] contains discreteOrderItem.category.id.intValue())");
    orderProcessor.filterOrderLevelOffer(order, qualifiedOffers, offers.get(0));
    // test that the invalid order offer is excluded
    assertTrue(qualifiedOffers.size() == 0);
    verify();
}
Also used : PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)

Example 9 with PromotableOrder

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

the class OrderOfferProcessorTest method testCouldOrderItemMeetOfferRequirement.

public void testCouldOrderItemMeetOfferRequirement() throws Exception {
    replay();
    PromotableOrder order = dataProvider.createBasicPromotableOrder();
    List<Offer> offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", 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 = orderProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().get(0));
    // test that the valid order offer is included
    assertTrue(couldApply);
    offers = dataProvider.createOrderBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", 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 = orderProcessor.couldOrderItemMeetOfferRequirement(xref.getOfferItemCriteria(), order.getDiscountableOrderItems().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) OfferQualifyingCriteriaXref(org.broadleafcommerce.core.offer.domain.OfferQualifyingCriteriaXref)

Example 10 with PromotableOrder

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

the class OrderOfferProcessorImpl method synchronizeOrderItems.

protected void synchronizeOrderItems(PromotableOrder promotableOrder) {
    Order order = promotableOrder.getOrder();
    Map<OrderItem, PromotableOrderItem> promotableItemMap = offerServiceUtilities.buildPromotableItemMap(promotableOrder);
    List<OrderItem> orderItemList = offerServiceUtilities.buildOrderItemList(order);
    for (OrderItem orderItem : orderItemList) {
        PromotableOrderItem promotableItem = promotableItemMap.get(orderItem);
        if (promotableItem == null) {
            continue;
        }
        synchronizeItemPriceDetails(orderItem, promotableItem);
        synchronizeItemQualifiers(orderItem, promotableItem);
    }
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)

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