DeliveryAssemblerImpl implements DeliveryAssembler { @Override public CustomerOrder assembleCustomerOrder(final CustomerOrder order, final ShoppingCart shoppingCart, final Map<String, Boolean> onePhysicalDelivery) throws OrderAssemblyException { final Map<DeliveryBucket, List<CustomerOrderDet>> groups = getDeliveryGroups(order, onePhysicalDelivery); int idx = 0; for (Map.Entry<DeliveryBucket, List<CustomerOrderDet>> entry : groups.entrySet()) { final List<CustomerOrderDet> items = entry.getValue(); final CustomerOrderDelivery customerOrderDelivery = createOrderDelivery( order, shoppingCart, items, entry.getKey(), idx); if (CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(entry.getKey().getGroup())) { customerOrderDelivery.setPrice(BigDecimal.ZERO); customerOrderDelivery.setListPrice(BigDecimal.ZERO); customerOrderDelivery.setPromoApplied(false); customerOrderDelivery.setAppliedPromo(null); customerOrderDelivery.setNetPrice(BigDecimal.ZERO); customerOrderDelivery.setGrossPrice(BigDecimal.ZERO); customerOrderDelivery.setTaxCode(""); customerOrderDelivery.setTaxRate(BigDecimal.ZERO); } else { final Total cartTotal = shoppingCart.getTotal(); final String shippingSlaGUID = customerOrderDelivery.getCarrierSla().getGuid(); final CartItem shipping = shoppingCart.getShippingListMap().get(entry.getKey()) .stream().filter(item -> shippingSlaGUID.equals(item.getProductSkuCode())) .findFirst().orElse(null); if (cartTotal == null || shipping == null || shipping.getListPrice() == null || shipping.getPrice() == null || shipping.getNetPrice() == null || shipping.getGrossPrice() == null || shipping.getTaxRate() == null || shipping.getTaxCode() == null) { throw new OrderAssemblyException("No delivery total for: " + entry.getKey()); } customerOrderDelivery.setPrice(shipping.getPrice()); customerOrderDelivery.setListPrice(shipping.getListPrice()); customerOrderDelivery.setPromoApplied(shipping.isPromoApplied()); customerOrderDelivery.setAppliedPromo(shipping.getAppliedPromo()); customerOrderDelivery.setNetPrice(shipping.getNetPrice()); customerOrderDelivery.setGrossPrice(shipping.getGrossPrice()); customerOrderDelivery.setTaxCode(shipping.getTaxCode()); customerOrderDelivery.setTaxRate(shipping.getTaxRate()); customerOrderDelivery.setTaxExclusiveOfPrice(shipping.isTaxExclusiveOfPrice()); final String requestedDateKey = AttributeNamesKeys.Cart.ORDER_INFO_REQUESTED_DELIVERY_DATE_ID + customerOrderDelivery.getCarrierSla().getCarrierslaId() + entry.getKey().getSupplier(); final LocalDateTime requestedDate = DateUtils.ldtFrom( NumberUtils.toLong(shoppingCart.getOrderInfo().getDetailByKey(requestedDateKey), 0) ); if (requestedDate.isAfter(now())) { customerOrderDelivery.setRequestedDeliveryDate(requestedDate); } } order.getDelivery().add(customerOrderDelivery); idx++; } return order; } DeliveryAssemblerImpl(final WarehouseService warehouseService,
                                 final CarrierSlaService carrierSlaService,
                                 final OrderSplittingStrategy orderSplittingStrategy); @Override CustomerOrder assembleCustomerOrder(final CustomerOrder order,
                                               final ShoppingCart shoppingCart,
                                               final Map<String, Boolean> onePhysicalDelivery); @Override Map<String, Boolean> isOrderMultipleDeliveriesAllowed(final CustomerOrder order);  }
@Test public void testGetDeliveryGroupsStandardInsufficient() throws Exception { Customer customer = createCustomer(); assertFalse(customer.getAddress().isEmpty()); ShoppingCart shoppingCart = getShoppingCart2(customer.getEmail()); try { CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, RandomStringUtils.random(10)); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, getMultiSelection(shoppingCart)); fail("Must not allow creating orders with unavailable SKU"); } catch (SkuUnavailableException sue) { assertEquals("Sku CC_TEST4-M:cc test 4 m is not available, cause: offline", sue.getMessage()); } }
@Test public void testAssembleCustomerOrder() throws Exception { Customer customer = createCustomer(); assertFalse(customer.getAddress().isEmpty()); ShoppingCart shoppingCart = getShoppingCart7(customer.getEmail()); CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, RandomStringUtils.random(10)); assertNotNull("Customer can not be null", shoppingCart.getCustomerEmail()); customerOrder = deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, getMultiSelection(shoppingCart)); customerOrder = customerOrderService.create(customerOrder); assertTrue(customerOrder.getCustomerorderId() > 0); for (CustomerOrderDelivery cod : customerOrder.getDelivery()) { assertTrue(cod.getCustomerOrderDeliveryId() > 0); assertNotNull(cod.getDeliveryNum()); if (CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(cod.getDeliveryGroup())) { assertEquals(BigDecimal.ZERO, cod.getPrice()); assertEquals(BigDecimal.ZERO, cod.getNetPrice()); assertEquals(BigDecimal.ZERO, cod.getGrossPrice()); assertEquals(BigDecimal.ZERO, cod.getTaxRate()); assertEquals("", cod.getTaxCode()); assertFalse(cod.isTaxExclusiveOfPrice()); } else { assertEquals(new BigDecimal("16.77"), cod.getPrice()); assertEquals(new BigDecimal("13.97"), cod.getNetPrice()); assertEquals(new BigDecimal("16.77"), cod.getGrossPrice()); assertEquals(new BigDecimal("20.00"), cod.getTaxRate()); assertEquals("VAT", cod.getTaxCode()); assertFalse(cod.isTaxExclusiveOfPrice()); } for (CustomerOrderDeliveryDet det : cod.getDetail()) { assertTrue(det.getCustomerOrderDeliveryDetId() > 0); assertTrue(MoneyUtils.isPositive(det.getQty())); } } }