Set<OrderShipment> orderShipments = new HashSet<OrderShipment>();
Set<DeliveryMethod> deliveryMethods = cart.getDeliveryMethods();
if(deliveryMethods != null){
for (Iterator<DeliveryMethod> iteratorDeliveryMethod = deliveryMethods.iterator(); iteratorDeliveryMethod.hasNext();) {
DeliveryMethod deliveryMethod = (DeliveryMethod) iteratorDeliveryMethod.next();
OrderShipment orderShipment = new OrderShipment();
orderShipment.setName(deliveryMethod.getName());
orderShipment.setExpectedDeliveryDate(null);
orderShipment.setDeliveryMethodId(deliveryMethod.getId());
orderShipment.setPrice(deliveryMethod.getPrice(cart.getCurrency().getId()));
Set<CartItem> cartItems = cart.getCartItems();
Set<OrderItem> orderItems = new HashSet<OrderItem>();
for (Iterator<CartItem> iteratorCartItem = cartItems.iterator(); iteratorCartItem.hasNext();) {
CartItem cartItem = (CartItem) iteratorCartItem.next();
OrderItem orderItem = new OrderItem();
orderItem.setCurrency(cart.getCurrency());
orderItem.setProductSkuCode(cartItem.getProductSkuCode());
orderItem.setProductSku(cartItem.getProductSku());
orderItem.setPrice(cartItem.getPrice(cart.getMarketAreaId(), cart.getRetailerId()).getSalePrice());
orderItem.setQuantity(cartItem.getQuantity());
// TAXES
Set<CartItemTax> taxes = cartItem.getTaxes();
if(taxes != null){
for (Iterator<CartItemTax> iteratorCartItemTax = taxes.iterator(); iteratorCartItemTax.hasNext();) {
CartItemTax cartItemTax = (CartItemTax) iteratorCartItemTax.next();
OrderTax orderTax = new OrderTax();
orderTax.setName(cartItemTax.getTax().getName());
orderTax.setPercent(cartItemTax.getTax().getPercent());
orderTax.setAmount(cartItemTax.getTaxAmount());
orderItem.getOrderTaxes().add(orderTax);
}
}
orderItems.add(orderItem);
}
orderShipment.setOrderItems(orderItems);
orderShipments.add(orderShipment);
}
}
orderCustomer.setOrderShipments(orderShipments);