use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CartTest method testAddItemToCartFromNamedOrder.
@Test(groups = { "testCartAndNamedOrder" })
@Transactional
public void testAddItemToCartFromNamedOrder() throws RemoveFromCartException, AddToCartException {
Order namedOrder = setUpNamedOrder();
List<OrderItem> namedOrderItems = new ArrayList<>();
namedOrderItems.addAll(namedOrder.getOrderItems());
List<OrderItem> movedOrderItems = new ArrayList<>();
movedOrderItems.add(namedOrderItems.get(0));
Order cart = orderService.createNewCartForCustomer(namedOrder.getCustomer());
orderService.setMoveNamedOrderItems(false);
cart = orderService.addItemFromNamedOrder(namedOrder, movedOrderItems.get(0), true);
orderService.setMoveNamedOrderItems(true);
assert cartContainsOnlyTheseItems(cart, movedOrderItems);
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CartTest method testAddAllItemsToCartFromNamedOrder.
@Test(groups = { "testCartAndNamedOrder" })
@Transactional
public void testAddAllItemsToCartFromNamedOrder() throws RemoveFromCartException, AddToCartException {
Order namedOrder = setUpNamedOrder();
List<OrderItem> namedOrderItems = new ArrayList<>();
namedOrderItems.addAll(namedOrder.getOrderItems());
Order cart = orderService.createNewCartForCustomer(namedOrder.getCustomer());
orderService.setMoveNamedOrderItems(false);
cart = orderService.addAllItemsFromNamedOrder(namedOrder, true);
orderService.setMoveNamedOrderItems(true);
assert cartContainsOnlyTheseItems(cart, namedOrderItems);
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CartTest method testMoveItemToCartFromNamedOrderWithoutExistingCart.
@Test(groups = { "testCartAndNamedOrder" })
@Transactional
public void testMoveItemToCartFromNamedOrderWithoutExistingCart() throws RemoveFromCartException, AddToCartException {
Order namedOrder = setUpNamedOrder();
List<OrderItem> namedOrderItems = new ArrayList<>();
namedOrderItems.addAll(namedOrder.getOrderItems());
List<OrderItem> movedOrderItems = new ArrayList<>();
movedOrderItems.add(namedOrderItems.get(0));
Order cart = orderService.addItemFromNamedOrder(namedOrder, movedOrderItems.get(0), true);
List<Order> customerNamedOrders = orderService.findOrdersForCustomer(namedOrder.getCustomer(), OrderStatus.NAMED);
assert customerNamedOrders.size() == 0;
assert cart.getOrderItems().size() == 1;
assert namedOrder.getOrderItems().size() == 0;
assert cartContainsOnlyTheseItems(cart, movedOrderItems);
}
use of org.broadleafcommerce.core.order.domain.OrderItem 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.order.domain.OrderItem 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())));
}
Aggregations