Search in sources :

Example 11 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutTest method testCheckout.

@Test(groups = { "checkout" }, dependsOnGroups = { "createCartForCustomer", "testShippingInsert" }, dataProvider = "USCurrency", dataProviderClass = BroadleafCurrencyProvider.class)
@Transactional
public void testCheckout(BroadleafCurrency usCurrency) throws Exception {
    HashMap currencyConsiderationContext = new HashMap();
    currencyConsiderationContext.put("aa", "bb");
    CurrencyConversionContext.setCurrencyConversionContext(currencyConsiderationContext);
    CurrencyConversionContext.setCurrencyConversionService(new CurrencyConversionService() {

        @Override
        public Money convertCurrency(Money source, Currency destinationCurrency, int destinationScale) {
            return source;
        }
    });
    String userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    Order order = orderService.createNewCartForCustomer(customer);
    usCurrency = currencyService.save(usCurrency);
    order.setCurrency(usCurrency);
    Address address = buildAddress();
    FulfillmentGroup group = buildFulfillmentGroup(order, address);
    addSampleItemToOrder(order, group);
    order.setTotalShipping(new Money(0D));
    addPaymentToOrder(order, address);
    // execute pricing for this order
    orderService.save(order, true);
    CheckoutResponse response = checkoutService.performCheckout(order);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Address(org.broadleafcommerce.profile.core.domain.Address) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer) Currency(java.util.Currency) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CurrencyConversionService(org.broadleafcommerce.common.money.CurrencyConversionService) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Money

use of org.broadleafcommerce.common.money.Money 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;
}
Also used : DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 13 with Money

use of org.broadleafcommerce.common.money.Money 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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test)

Example 14 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class MVELTest method testOfferAppliesToSpecificItems.

@Test
public void testOfferAppliesToSpecificItems() {
    DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl();
    Sku sku = new SkuImpl();
    sku.setRetailPrice(new Money("1"));
    sku.setId(1234L);
    orderItem.setSku(sku);
    OfferImpl offer = new OfferImpl();
    offer.setType(OfferType.ORDER_ITEM);
    // 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
    Serializable domainExp1 = MVEL.compileExpression("offer.type == OfferType.ORDER_ITEM and (currentItem.sku.id in [1234, 2345, 5678])", context);
    // Add variables to a HashMap that should be passed in to execute the expression
    HashMap<String, Object> domainVars = new HashMap<>();
    domainVars.put("currentItem", orderItem);
    domainVars.put("offer", offer);
    // Execute the expression
    Boolean expressionOutcome1 = (Boolean) MVEL.executeExpression(domainExp1, domainVars);
    assert expressionOutcome1 != null && expressionOutcome1;
}
Also used : Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Serializable(java.io.Serializable) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) HashMap(java.util.HashMap) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test)

Example 15 with Money

use of org.broadleafcommerce.common.money.Money 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;
}
Also used : Serializable(java.io.Serializable) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) ParserContext(org.mvel2.ParserContext) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Money (org.broadleafcommerce.common.money.Money)158 Order (org.broadleafcommerce.core.order.domain.Order)43 BigDecimal (java.math.BigDecimal)38 Offer (org.broadleafcommerce.core.offer.domain.Offer)29 Test (org.testng.annotations.Test)29 Transactional (org.springframework.transaction.annotation.Transactional)24 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)22 ArrayList (java.util.ArrayList)21 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)21 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)19 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 HashMap (java.util.HashMap)12 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)12 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)11 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)11 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)10