use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method orderMeetsProvidedSubtotalRequirement.
protected boolean orderMeetsProvidedSubtotalRequirement(Offer offer, HashMap<OfferItemCriteria, List<PromotableOrderItem>> promotableOrderItems, Money minSubTotal) {
Money subtotal = Money.ZERO;
for (OfferItemCriteria itemCriteria : promotableOrderItems.keySet()) {
List<PromotableOrderItem> promotableItems = promotableOrderItems.get(itemCriteria);
for (PromotableOrderItem item : promotableItems) {
boolean shouldApplyDiscountToSalePrice = offer.getApplyDiscountToSalePrice();
Money priceBeforeAdjustments = item.getPriceBeforeAdjustments(shouldApplyDiscountToSalePrice);
int quantity = item.getQuantity();
Money lineItemAmount = priceBeforeAdjustments.multiply(quantity);
subtotal = subtotal.add(lineItemAmount);
if (subtotal.greaterThanOrEqual(minSubTotal)) {
return true;
}
}
}
return false;
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem 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();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem 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();
}
use of org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem 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);
}
Aggregations