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);
}
}
}
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())));
}
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);
}
}
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);
}
}
}
}
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())));
}
Aggregations