use of org.broadleafcommerce.common.money.Money 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.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class ItemOfferProcessorTest method testApplyAllItemOffers.
public void testApplyAllItemOffers() throws Exception {
replay();
Order order = dataProvider.createBasicOrder();
Offer offer1 = 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);
offer1.setId(1L);
List<Offer> offers = new ArrayList<Offer>();
offers.add(offer1);
List<PromotableCandidateItemOffer> qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
order.updatePrices();
offerService.applyAndSaveOffersToOrder(offers, order);
assertTrue(order.getTotalAdjustmentsValue().getAmount().doubleValue() > 0);
order = dataProvider.createBasicOrder();
qualifiedOffers = new ArrayList<PromotableCandidateItemOffer>();
offer1.setApplyDiscountToSalePrice(false);
((DiscreteOrderItem) order.getOrderItems().get(0)).getSku().setSalePrice(new Money(1D));
((DiscreteOrderItem) order.getOrderItems().get(1)).getSku().setSalePrice(new Money(1D));
order.updatePrices();
offerService.applyAndSaveOffersToOrder(offers, order);
assertTrue(order.getTotalAdjustmentsValue().getAmount().doubleValue() == 0);
verify();
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class BandedPriceFulfillmentTest method testPriceBandRate.
public void testPriceBandRate() throws Exception {
BandedPriceFulfillmentOption option = createPriceBands(new String[] { "10", "20", "30" }, new String[] { "10", "20", "30" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE });
assertEquals(new Money("20.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("20.00"), 2, option)));
assertEquals(Money.ZERO, calculationResponse(option, createCandidateOrder(new BigDecimal("9.00"), 3, option)));
assertEquals(new Money("30.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("30.00"), 3, option)));
assertEquals(new Money("20.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("25.00"), 5, option)));
assertEquals(new Money("30.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("100.00"), 5, option)));
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class BandedPriceFulfillmentTest method testPriceBandRatesWithPercentages.
public void testPriceBandRatesWithPercentages() throws Exception {
BandedPriceFulfillmentOption option = createPriceBands(new String[] { "150", "30", "20", "150", "10", "9", "80" }, new String[] { "50", "20", ".30", "20", ".10", "5", ".5" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.PERCENTAGE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.PERCENTAGE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.PERCENTAGE });
assertEquals(new Money("20"), calculationResponse(option, createCandidateOrder(new BigDecimal("35.00"), 5, option)));
assertEquals(new Money("20"), calculationResponse(option, createCandidateOrder(new BigDecimal("9999.00"), 9, option)));
assertEquals(new Money("7.50"), calculationResponse(option, createCandidateOrder(new BigDecimal("25.00"), 5, option)));
assertEquals(new Money("1.80"), calculationResponse(option, createCandidateOrder(new BigDecimal("18.00"), 6, option)));
assertEquals(new Money("50"), calculationResponse(option, createCandidateOrder(new BigDecimal("100.00"), 5, option)));
assertEquals(new Money("5"), calculationResponse(option, createCandidateOrder(new BigDecimal("9.00"), 3, option)));
assertEquals(new Money("20"), calculationResponse(option, createCandidateOrder(new BigDecimal("66"), 6, option)));
assertEquals(new Money("20"), calculationResponse(option, createCandidateOrder(new BigDecimal("150"), 5, option)));
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class BandedPriceFulfillmentTest method testWeightBandsWithQuantities.
public void testWeightBandsWithQuantities() throws Exception {
BandedWeightFulfillmentOption option = createWeightBands(new String[] { "50", "100", "65" }, new String[] { "30", "20", "10" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE });
// 60lbs
assertEquals(new Money("30"), calculationResponse(option, createCandidateOrder(new BigDecimal("18.00"), 3, null, new int[] { 2, 3, 5 }, option)));
// 66lbs
assertEquals(new Money("10"), calculationResponse(option, createCandidateOrder(new BigDecimal("18.00"), 6, null, new int[] { 4, 1, 2, 5, 5, 5 }, option)));
// 120lbs
assertEquals(new Money("20"), calculationResponse(option, createCandidateOrder(new BigDecimal("60.00"), 3, null, new int[] { 2, 3, 2 }, option)));
}
Aggregations