Search in sources :

Example 1 with OrderAdjustmentImpl

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);
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) BigDecimal(java.math.BigDecimal)

Example 2 with OrderAdjustmentImpl

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())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Example 3 with OrderAdjustmentImpl

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())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Example 4 with OrderAdjustmentImpl

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())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Example 5 with OrderAdjustmentImpl

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));
            }
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) Money(org.broadleafcommerce.common.money.Money) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)5 Money (org.broadleafcommerce.common.money.Money)5 OrderAdjustment (org.broadleafcommerce.core.offer.domain.OrderAdjustment)5 OrderAdjustmentImpl (org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl)5 Order (org.broadleafcommerce.core.order.domain.Order)5 DefaultProcessContextImpl (org.broadleafcommerce.core.workflow.DefaultProcessContextImpl)5 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)4 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)2