use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class CandidateItemOfferTest method setUp.
@Override
protected void setUp() throws Exception {
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
CandidateItemOfferImpl candidate = new CandidateItemOfferImpl();
Category category1 = new CategoryImpl();
category1.setName("test1");
category1.setId(1L);
Product product1 = new ProductImpl();
Sku sku1 = new SkuImpl();
sku1.setName("test1");
sku1.setDiscountable(true);
sku1.setRetailPrice(new Money(19.99D));
product1.setDefaultSku(sku1);
CategoryProductXref xref1 = new CategoryProductXrefImpl();
xref1.setProduct(product1);
xref1.setCategory(category1);
category1.getAllProductXrefs().add(xref1);
Category category2 = new CategoryImpl();
category2.setName("test2");
category2.setId(2L);
Product product2 = new ProductImpl();
Sku sku2 = new SkuImpl();
sku2.setName("test2");
sku2.setDiscountable(true);
sku2.setRetailPrice(new Money(29.99D));
product2.setDefaultSku(sku2);
CategoryProductXref xref2 = new CategoryProductXrefImpl();
xref2.setProduct(product2);
xref2.setCategory(category2);
category2.getAllProductXrefs().add(xref2);
DiscreteOrderItemImpl orderItem1 = new DiscreteOrderItemImpl();
orderItem1.setCategory(category1);
orderItem1.setName("test1");
orderItem1.setOrderItemType(OrderItemType.DISCRETE);
orderItem1.setProduct(product1);
orderItem1.setQuantity(2);
orderItem1.setSku(sku1);
Order order = new OrderImpl();
orderItem1.setOrder(order);
promotableOrder = new PromotableOrderImpl(order, new PromotableItemFactoryImpl(), false);
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);
promotableOrderItem = new PromotableOrderItemImpl(orderItem1, null, new PromotableItemFactoryImpl(), false);
OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl();
pdetail.setOrderItem(orderItem1);
pdetail.setQuantity(2);
priceDetail = new PromotableOrderItemPriceDetailImpl(promotableOrderItem, 2);
List<PromotableOrderItem> items = new ArrayList<PromotableOrderItem>();
items.add(promotableOrderItem);
promotableCandidate = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
OfferTargetCriteriaXref xref = offer.getTargetItemCriteriaXref().iterator().next();
promotableCandidate.getCandidateTargetsMap().put(xref.getOfferItemCriteria(), items);
}
use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class MVELTest method testOfferAppliesToHatsWhenOneLawnmowerIsPurchased.
// @Test
// TODO fix this test
public void testOfferAppliesToHatsWhenOneLawnmowerIsPurchased() {
OrderImpl order = new OrderImpl();
ArrayList<OrderItem> items = new ArrayList<>();
order.setOrderItems(items);
DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
Money amount = new Money(10D);
items.add(item);
item.setSalePrice(amount);
ProductImpl product = new ProductImpl();
CategoryImpl category = new CategoryImpl();
category.setName("hat");
product.setDefaultCategory(category);
item.setProduct(product);
item.setQuantity(3);
DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
Money amount2 = new Money(250D);
items.add(item2);
item2.setSalePrice(amount2);
ProductImpl product2 = new ProductImpl();
CategoryImpl category2 = new CategoryImpl();
category2.setName("lawnmower");
product2.setDefaultCategory(category2);
item2.setProduct(product2);
item2.setQuantity(1);
HashMap<String, Object> vars = new HashMap<>();
vars.put("currentItem", item);
vars.put("order", order);
vars.put("doMark", false);
// This test makes use of the static MVEL function "orderContains(quantity)".
StringBuffer expression = new StringBuffer(functions);
expression.append("def evalItemForOrderContains(item) {").append(" return item.product.defaultCategory.name == 'lawnmower'").append(" } ").append(" return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
Boolean result = (Boolean) MVEL.eval(expression.toString(), vars);
assert result != null && result;
}
use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class MVELTest method testOfferAppliesToFulfillmentGroup.
// @Test
// No longer a valid test
// public void testMarkLawnmowerWhenOfferAppliesToHats() {
// OrderImpl order = new OrderImpl();
// ArrayList<OrderItem> items = new ArrayList<OrderItem>();
// order.setOrderItems(items);
// DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
// Money amount = new Money(10D);
// items.add(item);
// item.setSalePrice(amount);
// ProductImpl product = new ProductImpl();
// CategoryImpl category = new CategoryImpl();
// category.setName("hat");
// product.setDefaultCategory(category);
// item.setProduct(product);
// item.setQuantity(3);
//
// DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
// Money amount2 = new Money(250D);
// items.add(item2);
// item2.setSalePrice(amount2);
// ProductImpl product2 = new ProductImpl();
// CategoryImpl category2 = new CategoryImpl();
// category2.setName("lawnmower");
// product2.setDefaultCategory(category2);
// item2.setProduct(product2);
// item2.setQuantity(1);
//
// HashMap<String, Object> vars = new HashMap<String, Object>();
// vars.put("currentItem", item);
// vars.put("order", order);
// vars.put("doMark", true);
//
// //This test makes use of the static MVEL function "orderContains(quantity)".
// StringBuffer expression = new StringBuffer(functions);
// expression.append("def evalItemForOrderContains(item) {")
// .append(" return item.product.defaultCategory.name == 'lawnmower'")
// .append(" } ")
// .append(" return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
//
// Boolean result = (Boolean)MVEL.eval(expression.toString(), vars);
// assert result != null && result;
// assert item2.getMarkedForOffer() == 1;
// assert item.getMarkedForOffer() == 0;
// }
@Test
public void testOfferAppliesToFulfillmentGroup() {
OrderImpl order = new OrderImpl();
order.setSubTotal(new Money(110D));
FulfillmentGroupImpl group = new FulfillmentGroupImpl();
group.setPrimary(true);
OfferImpl offer = new OfferImpl();
offer.setType(OfferType.FULFILLMENT_GROUP);
order.getFulfillmentGroups().add(group);
// Set up MVEL Context
ParserContext context = new ParserContext();
// Import OfferType into the MVEL context since it may be used
context.addImport("OfferType", OfferType.class);
context.addImport("FulfillmentType", FulfillmentType.class);
// Compile the MVEL Expression
// This could test SHIPPING, or PICK_UP_AT_STORE, etc.
// Could also apply to order instead of FULFILLMENT_GROUP
Serializable domainExp1 = MVEL.compileExpression("offer.type.equals(OfferType.FULFILLMENT_GROUP) and (($ in order.fulfillmentGroups if $.type.equals(FulfillmentType.PHYSICAL)) != empty)", context);
// Add variables to a HashMap that should be passed in to execute the expression
HashMap<String, Object> domainVars = new HashMap<>();
domainVars.put("order", order);
domainVars.put("offer", offer);
// Execute the expression
Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
assert expressionOutcome1 != null && expressionOutcome1;
}
use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class MVELTest method testOfferAppliesToItemsInCategoryAndOrderValueGreaterThanFifty.
@Test
@Transactional
public void testOfferAppliesToItemsInCategoryAndOrderValueGreaterThanFifty() {
// ----------------------------------------------------------------------------------------------------
// Mock up some order data
OrderImpl order = new OrderImpl();
CategoryImpl category = new CategoryImpl();
category.setName("t-shirt");
Product product = createProduct();
DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl();
ArrayList<CategoryProductXref> categories = new ArrayList<>();
CategoryProductXref categoryXref = new CategoryProductXrefImpl();
categoryXref.setProduct(product);
categoryXref.setCategory(category);
categories.add(categoryXref);
product.setAllParentCategoryXrefs(categories);
orderItem.setProduct(product);
order.getOrderItems().add(orderItem);
order.setSubTotal(new Money(110D));
// Set up MVEL Context
ParserContext context = new ParserContext();
// Import OfferType into the MVEL context since it may be used
context.addImport("OfferType", OfferType.class);
// Compile the MVEL Expression
Serializable domainExp1 = MVEL.compileExpression("result = false; for (cat : currentItem.product.allParentCategories) {if (cat.name == 't-shirt') {result = true;}}; return result and order.subTotal.amount >= 50", context);
// Add variables to a HashMap that should be passed in to execute the expression
HashMap<String, Object> domainVars = new HashMap<>();
domainVars.put("order", order);
domainVars.put("currentItem", orderItem);
// Execute the expression
Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
assert expressionOutcome1 != null && expressionOutcome1;
// Do the same thing using a different expression.
Serializable domainExp2 = MVEL.compileExpression("($ in currentItem.product.allParentCategories if $.name == 't-shirt') != empty and order.subTotal.amount >= 50", context);
Boolean expressionOutcome2 = (Boolean) MVEL.executeExpression(domainExp2, domainVars);
assert expressionOutcome2 != null && expressionOutcome2;
}
use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.
the class OrderDataProvider method provideBasicSalesOrder.
@DataProvider(name = "basicOrder")
public static Object[][] provideBasicSalesOrder() {
OrderImpl so = new OrderImpl();
so.setStatus(OrderStatus.IN_PROCESS);
so.setTotal(new Money(BigDecimal.valueOf(1000)));
return new Object[][] { { so } };
}
Aggregations