Search in sources :

Example 6 with OrderAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderAdjustment 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 7 with OrderAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderAdjustment 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

OrderAdjustment (org.broadleafcommerce.core.offer.domain.OrderAdjustment)7 Order (org.broadleafcommerce.core.order.domain.Order)6 BigDecimal (java.math.BigDecimal)5 Money (org.broadleafcommerce.common.money.Money)5 OrderAdjustmentImpl (org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl)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 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)1 PromotableOrderAdjustment (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment)1