use of org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveEqualItems.
public void testDistributeOneDollarAcrossFiveEqualItems() throws Exception {
Order order = dataProvider.createBasicOrder();
Money subTotal = new Money(order.getCurrency());
for (OrderItem orderItem : order.getOrderItems()) {
orderItem.setSalePrice(new Money(10D));
orderItem.getOrderItemPriceDetails().clear();
subTotal = subTotal.add(orderItem.getTotalPrice());
}
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
order.getOrderAdjustments().add(adjustment);
adjustment.setOrder(order);
order.setSubTotal(subTotal);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
// Each item is equally priced, so the adjustment should be .20 per item.
Money proratedAdjustment = new Money(".20");
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().compareTo(proratedAdjustment.multiply(fulfillmentGroupItem.getQuantity())) == 0);
}
}
}
use of org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testBundleDistribution.
public void testBundleDistribution() throws Exception {
Order order = dataProvider.createOrderWithBundle();
Money subTotal = new Money(order.getCurrency());
for (OrderItem orderItem : order.getOrderItems()) {
subTotal = subTotal.add(orderItem.getTotalPrice());
}
order.setSubTotal(subTotal);
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
adjustment.setOrder(order);
order.getOrderAdjustments().add(adjustment);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal("1"), order.getCurrency())));
}
use of org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testBundleDistributionWithoutItemSum.
public void testBundleDistributionWithoutItemSum() throws Exception {
Order order = dataProvider.createOrderWithBundle();
Money subTotal = new Money(order.getCurrency());
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bItem = (BundleOrderItem) orderItem;
bItem.getProductBundle().setPricingModel(ProductBundlePricingModelType.BUNDLE);
}
subTotal = subTotal.add(orderItem.getTotalPrice());
}
order.setSubTotal(subTotal);
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
adjustment.setOrder(order);
order.getOrderAdjustments().add(adjustment);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal("1"), order.getCurrency())));
}
use of org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testRoundingRequired.
public void testRoundingRequired() throws Exception {
Order order = dataProvider.createBasicOrder();
Money subTotal = new Money(order.getCurrency());
for (OrderItem orderItem : order.getOrderItems()) {
orderItem.getOrderItemPriceDetails().clear();
orderItem.setQuantity(2);
orderItem.setSalePrice(new Money(10D));
subTotal = subTotal.add(orderItem.getTotalPrice());
}
order.setSubTotal(subTotal);
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal(".05"), order.getCurrency()));
adjustment.setOrder(order);
order.getOrderAdjustments().add(adjustment);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal(".05"), order.getCurrency())));
}
use of org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveItems.
public void testDistributeOneDollarAcrossFiveItems() throws Exception {
Order order = dataProvider.createBasicOrder();
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
adjustment.setOrder(order);
order.getOrderAdjustments().add(adjustment);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
Money adj1 = new Money(".31");
Money adj2 = new Money(".69");
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
if (fulfillmentGroupItem.getSalePrice().equals(new Money("19.99"))) {
assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().equals(adj1));
} else {
assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().equals(adj2));
}
}
}
}
Aggregations