Search in sources :

Example 1 with OrderAdjustment

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

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

use of org.broadleafcommerce.core.offer.domain.OrderAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class OrderOfferProcessorImpl method synchronizeOrderAdjustments.

protected void synchronizeOrderAdjustments(PromotableOrder promotableOrder) {
    Order order = promotableOrder.getOrder();
    if (order.getOrderAdjustments().isEmpty() && promotableOrder.getCandidateOrderAdjustments().isEmpty()) {
        return;
    }
    Map<Long, PromotableOrderAdjustment> newAdjustmentsMap = buildPromotableOrderAdjustmentsMap(promotableOrder);
    Iterator<OrderAdjustment> orderAdjIterator = order.getOrderAdjustments().iterator();
    while (orderAdjIterator.hasNext()) {
        OrderAdjustment adjustment = orderAdjIterator.next();
        if (adjustment.getOffer() != null) {
            Long offerId = adjustment.getOffer().getId();
            PromotableOrderAdjustment promotableAdjustment = newAdjustmentsMap.remove(offerId);
            if (promotableAdjustment != null) {
                if (!adjustment.getValue().equals(promotableAdjustment.getAdjustmentValue())) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Updating value for order adjustment with offer Id " + offerId + " to " + promotableAdjustment.getAdjustmentValue());
                    }
                    adjustment.setValue(promotableAdjustment.getAdjustmentValue());
                }
            } else {
                // No longer using this order adjustment, remove it.
                orderAdjIterator.remove();
            }
        }
    }
    for (PromotableOrderAdjustment promotableOrderAdjustment : newAdjustmentsMap.values()) {
        // Add the newly introduced adjustments.
        Offer offer = promotableOrderAdjustment.getOffer();
        OrderAdjustment orderAdjustment = offerDao.createOrderAdjustment();
        orderAdjustment.init(order, offer, offer.getName());
        orderAdjustment.setValue(promotableOrderAdjustment.getAdjustmentValue());
        order.getOrderAdjustments().add(orderAdjustment);
    }
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableOrderAdjustment(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderAdjustment)

Example 4 with OrderAdjustment

use of org.broadleafcommerce.core.offer.domain.OrderAdjustment in project BroadleafCommerce by BroadleafCommerce.

the class PromotableOrderImpl method createExistingOrderAdjustments.

/**
 * Bring over the order adjustments.   Intended to be used when processing
 * fulfillment orders.
 */
protected void createExistingOrderAdjustments() {
    if (order.getOrderAdjustments() != null) {
        for (OrderAdjustment adjustment : order.getOrderAdjustments()) {
            if (adjustment.getOffer() != null) {
                PromotableCandidateOrderOffer pcoo = itemFactory.createPromotableCandidateOrderOffer(this, adjustment.getOffer(), adjustment.getValue());
                PromotableOrderAdjustment adj = itemFactory.createPromotableOrderAdjustment(pcoo, this, adjustment.getValue());
                candidateOrderOfferAdjustments.add(adj);
            }
        }
    }
}
Also used : OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment)

Example 5 with OrderAdjustment

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

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