@Test public void testAssembleShoppingCartOsNoneNoDeliveries() throws Exception { Customer customer = createCustomer(); ShoppingCart shoppingCart = getShoppingCart2(customer.getEmail(), true); setIPAddress(shoppingCart, "127.0.0.1"); setCustomOrderDetail(shoppingCart, "someDetail", "order detail"); setCustomItemDetail(shoppingCart, "WAREHOUSE_1", "CC_TEST1", "someDetail", "item detail"); CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, UUID.randomUUID().toString()); assertNotNull(customerOrder); customerOrder = customerOrderService.create(customerOrder); assertNotNull(customerOrder); assertNotNull(customerOrder.getBillingAddress()); assertEquals("By default billing and shipping addresses the same", customerOrder.getBillingAddress(), customerOrder.getShippingAddress()); assertTrue("By Default billing address is shipping address ", customerOrder.getBillingAddress().contains("shipping addr")); assertEquals("Order must be in ORDER_STATUS_NONE state", CustomerOrder.ORDER_STATUS_NONE, customerOrder.getOrderStatus()); assertNotNull("Order num must be set", customerOrder.getOrdernum()); assertTrue("Order delivery assembler was not applied", customerOrder.getDelivery().isEmpty()); assertEquals("Shopping cart guid and order guid are equals", shoppingCart.getGuid(), customerOrder.getGuid()); assertEquals("127.0.0.1", customerOrder.getOrderIp()); assertEquals(8, customerOrder.getOrderDetail().size()); assertFalse(customerOrder.isMultipleShipmentOption()); assertEquals(new BigDecimal("5463.91"), customerOrder.getListPrice()); assertEquals(new BigDecimal("5463.91"), customerOrder.getPrice()); assertEquals(new BigDecimal("4551.88"), customerOrder.getNetPrice()); assertEquals(new BigDecimal("5463.91"), customerOrder.getGrossPrice()); final ShoppingCart reassembledCart = orderDisassembler.assembleShoppingCart(customerOrder, false); assertNotNull(reassembledCart); assertTrue(reassembledCart.isModified()); assertEquals(customerOrder.getOrderDetail().size(), reassembledCart.getCartItemList().size()); assertEquals(0, reassembledCart.getShippingList().size()); assertEquals(0, reassembledCart.getCoupons().size()); for (final CartItem orderItem : customerOrder.getOrderDetail()) { final CartItem cartItem = reassembledCart.getCartItemList().stream().filter(item -> orderItem.getProductSkuCode().equals(item.getProductSkuCode()) && orderItem.getSupplierCode().equals(item.getSupplierCode())).findFirst().orElse(null); assertNotNull(cartItem); assertEquals(orderItem.getQty(), cartItem.getQty()); assertEquals(orderItem.getPrice(), cartItem.getPrice()); assertEquals(orderItem.getSalePrice(), cartItem.getSalePrice()); assertEquals(orderItem.getListPrice(), cartItem.getListPrice()); assertEquals(orderItem.getNetPrice(), cartItem.getNetPrice()); assertEquals(orderItem.getGrossPrice(), cartItem.getGrossPrice()); assertEquals(orderItem.getTaxRate(), cartItem.getTaxRate()); assertEquals(orderItem.getTaxCode(), cartItem.getTaxCode()); assertEquals(orderItem.isTaxExclusiveOfPrice(), cartItem.isTaxExclusiveOfPrice()); assertEquals(orderItem.isGift(), cartItem.isGift()); assertEquals(orderItem.isFixedPrice(), cartItem.isFixedPrice()); assertEquals(orderItem.isPromoApplied(), cartItem.isPromoApplied()); assertEquals(orderItem.getAppliedPromo(), cartItem.getAppliedPromo()); assertEquals(orderItem.getProductSkuCode(), cartItem.getProductSkuCode()); } final Total reassembledTotal = reassembledCart.getTotal(); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getListSubTotal()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getSaleSubTotal()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getNonSaleSubTotal()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getPriceSubTotal()); assertFalse(reassembledTotal.isOrderPromoApplied()); assertNull(reassembledTotal.getAppliedOrderPromo()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getSubTotal()); assertEquals(new BigDecimal("912.03"), reassembledTotal.getSubTotalTax()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getSubTotalAmount()); assertEquals(new BigDecimal("0.00"), reassembledTotal.getDeliveryListCost()); assertEquals(new BigDecimal("0.00"), reassembledTotal.getDeliveryCost()); assertFalse(reassembledTotal.isDeliveryPromoApplied()); assertNull(reassembledTotal.getAppliedDeliveryPromo()); assertEquals(new BigDecimal("0.00"), reassembledTotal.getDeliveryTax()); assertEquals(new BigDecimal("0.00"), reassembledTotal.getDeliveryCostAmount()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getTotal()); assertEquals(new BigDecimal("912.03"), reassembledTotal.getTotalTax()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getListTotalAmount()); assertEquals(new BigDecimal("5463.91"), reassembledTotal.getTotalAmount()); assertEquals(customerOrder.getEmail(), reassembledCart.getCustomerEmail()); assertEquals(customerOrder.getCurrency(), reassembledCart.getCurrencyCode()); assertEquals(customerOrder.getLocale(), reassembledCart.getCurrentLocale()); assertEquals(customerOrder.getOrdernum(), reassembledCart.getOrdernum()); final ShoppingContext reassembledSC = reassembledCart.getShoppingContext(); assertNotNull(reassembledSC.getCustomerName()); assertTrue(reassembledSC.getCustomerName().contains(customerOrder.getFirstname())); assertTrue(reassembledSC.getCustomerName().contains(customerOrder.getLastname())); assertEquals(10L, reassembledSC.getShopId()); assertEquals(10L, reassembledSC.getCustomerShopId()); assertEquals("SHOIP1", reassembledSC.getShopCode()); assertEquals("CA", reassembledSC.getCountryCode()); assertNull(reassembledSC.getStateCode()); assertNotNull(reassembledSC.getCustomerShops()); assertEquals(1, reassembledSC.getCustomerShops().size()); assertEquals("SHOIP1", reassembledSC.getCustomerShops().get(0)); assertEquals("127.0.0.1", reassembledSC.getResolvedIp()); final OrderInfo reassembledOI = reassembledCart.getOrderInfo(); assertNull(reassembledOI.getPaymentGatewayLabel()); assertFalse(reassembledOI.isMultipleDelivery()); assertFalse(reassembledOI.isSeparateBillingAddress()); assertFalse(reassembledOI.isBillingAddressNotRequired()); assertFalse(reassembledOI.isDeliveryAddressNotRequired()); assertNotNull(reassembledOI.getCarrierSlaId()); assertTrue(reassembledOI.getCarrierSlaId().isEmpty()); assertNotNull(reassembledOI.getBillingAddressId()); assertNotNull(reassembledOI.getDeliveryAddressId()); assertEquals("item detail", reassembledOI.getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_ATTRIBUTE_ID + "WAREHOUSE_1_CC_TEST1_someDetail")); assertEquals("order detail", reassembledOI.getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_ATTRIBUTE_ID + "_someDetail")); }
@Override public ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled) throws OrderAssemblyException { final ShoppingCartImpl shoppingCart = new ShoppingCartImpl(); shoppingCart.setPromotionsDisabled(promotionsDisabled); shoppingCart.setOrdernum(customerOrder.getOrdernum()); shoppingCart.initialise(amountCalculationStrategy); if (CollectionUtils.isEmpty(customerOrder.getDelivery())) { for (CustomerOrderDet orderDet : customerOrder.getOrderDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } else { for (CustomerOrderDelivery delivery : customerOrder.getDelivery()) { for (CustomerOrderDeliveryDet orderDet : delivery.getDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } } for(PromotionCouponUsage coupons : customerOrder.getCoupons()) { shoppingCart.addCoupon(coupons.getCouponCode()); } shoppingCart.setCurrentLocale(customerOrder.getLocale()); shoppingCart.setCurrencyCode(customerOrder.getCurrency()); MutableOrderInfo mutableOrderInfo = shoppingCart.getOrderInfo(); MutableShoppingContext mutableShoppingContext = shoppingCart.getShoppingContext(); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF, customerOrder.getB2bRef()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID, customerOrder.getB2bEmployeeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID, customerOrder.getB2bChargeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER, String.valueOf(customerOrder.isB2bRequireApprove())); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_BY, customerOrder.getB2bApprovedBy()); if (customerOrder.getB2bApprovedBy() != null) { mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_DATE, DateUtils.formatSDT(customerOrder.getB2bApprovedDate())); } mutableOrderInfo.setOrderMessage(customerOrder.getOrderMessage()); final Collection<CustomerOrderDelivery> deliveries = customerOrder.getDelivery(); final Map<String, Integer> noOfStdDeliveriesBySupplier = new HashMap<>(); boolean multi = false; final Map<String, Boolean> multiAvailable = new HashMap<>(); if (CollectionUtils.isNotEmpty(deliveries)) { for (final CustomerOrderDelivery delivery : deliveries) { final CartItem first = CollectionUtils.isNotEmpty(delivery.getDetail()) ? delivery.getDetail().iterator().next() : null; final String supplier = first != null && first.getSupplierCode() != null ? first.getSupplierCode() : ""; mutableOrderInfo.putCarrierSlaId(supplier, delivery.getCarrierSla().getCarrierslaId()); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(delivery.getDeliveryGroup())) { Integer count = noOfStdDeliveriesBySupplier.get(supplier); if (count == null) { noOfStdDeliveriesBySupplier.put(supplier, 1); multiAvailable.put(supplier, Boolean.FALSE); } else { noOfStdDeliveriesBySupplier.put(supplier, count + 1); multi = true; multiAvailable.put(supplier, Boolean.TRUE); } } } } mutableOrderInfo.setMultipleDelivery(multi); mutableOrderInfo.setMultipleDeliveryAvailable(multiAvailable); if (customerOrder.getBillingAddressDetails() != null) { mutableOrderInfo.setBillingAddressId(customerOrder.getBillingAddressDetails().getAddressId()); mutableShoppingContext.setCountryCode(customerOrder.getBillingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getBillingAddressDetails().getStateCode()); mutableOrderInfo.setBillingAddressNotRequired(false); } else { mutableOrderInfo.setBillingAddressNotRequired(true); } if (customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setDeliveryAddressId(customerOrder.getShippingAddressDetails().getAddressId()); if (mutableShoppingContext.getCountryCode() == null) { mutableShoppingContext.setCountryCode(customerOrder.getShippingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getShippingAddressDetails().getStateCode()); } mutableOrderInfo.setDeliveryAddressNotRequired(false); } else { mutableOrderInfo.setDeliveryAddressNotRequired(true); } if (customerOrder.getBillingAddressDetails() != null && customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setSeparateBillingAddress(!customerOrder.getBillingAddress().equals(customerOrder.getShippingAddress())); } else { mutableOrderInfo.setSeparateBillingAddress(false); } mutableOrderInfo.setPaymentGatewayLabel(customerOrder.getPgLabel()); mutableShoppingContext.setCustomerEmail(customerOrder.getEmail()); final Shop configShop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster() : customerOrder.getShop(); mutableShoppingContext.setCustomerName(formatNameFor(customerOrder, configShop)); final List<String> customerShops = new ArrayList<>(); customerShops.add(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShops(customerShops); if (customerOrder.getShop().getMaster() != null) { mutableShoppingContext.setShopId(customerOrder.getShop().getMaster().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getMaster().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } else { mutableShoppingContext.setShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } mutableShoppingContext.setResolvedIp(customerOrder.getOrderIp()); copyOrderCustomAttributes(shoppingCart, customerOrder.getAllValues()); shoppingCart.recalculate(); shoppingCart.markDirty(); return shoppingCart; }
OrderDisassemblerImpl implements OrderDisassembler { @Override public ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled) throws OrderAssemblyException { final ShoppingCartImpl shoppingCart = new ShoppingCartImpl(); shoppingCart.setPromotionsDisabled(promotionsDisabled); shoppingCart.setOrdernum(customerOrder.getOrdernum()); shoppingCart.initialise(amountCalculationStrategy); if (CollectionUtils.isEmpty(customerOrder.getDelivery())) { for (CustomerOrderDet orderDet : customerOrder.getOrderDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } else { for (CustomerOrderDelivery delivery : customerOrder.getDelivery()) { for (CustomerOrderDeliveryDet orderDet : delivery.getDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } } for(PromotionCouponUsage coupons : customerOrder.getCoupons()) { shoppingCart.addCoupon(coupons.getCouponCode()); } shoppingCart.setCurrentLocale(customerOrder.getLocale()); shoppingCart.setCurrencyCode(customerOrder.getCurrency()); MutableOrderInfo mutableOrderInfo = shoppingCart.getOrderInfo(); MutableShoppingContext mutableShoppingContext = shoppingCart.getShoppingContext(); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF, customerOrder.getB2bRef()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID, customerOrder.getB2bEmployeeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID, customerOrder.getB2bChargeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER, String.valueOf(customerOrder.isB2bRequireApprove())); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_BY, customerOrder.getB2bApprovedBy()); if (customerOrder.getB2bApprovedBy() != null) { mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_DATE, DateUtils.formatSDT(customerOrder.getB2bApprovedDate())); } mutableOrderInfo.setOrderMessage(customerOrder.getOrderMessage()); final Collection<CustomerOrderDelivery> deliveries = customerOrder.getDelivery(); final Map<String, Integer> noOfStdDeliveriesBySupplier = new HashMap<>(); boolean multi = false; final Map<String, Boolean> multiAvailable = new HashMap<>(); if (CollectionUtils.isNotEmpty(deliveries)) { for (final CustomerOrderDelivery delivery : deliveries) { final CartItem first = CollectionUtils.isNotEmpty(delivery.getDetail()) ? delivery.getDetail().iterator().next() : null; final String supplier = first != null && first.getSupplierCode() != null ? first.getSupplierCode() : ""; mutableOrderInfo.putCarrierSlaId(supplier, delivery.getCarrierSla().getCarrierslaId()); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(delivery.getDeliveryGroup())) { Integer count = noOfStdDeliveriesBySupplier.get(supplier); if (count == null) { noOfStdDeliveriesBySupplier.put(supplier, 1); multiAvailable.put(supplier, Boolean.FALSE); } else { noOfStdDeliveriesBySupplier.put(supplier, count + 1); multi = true; multiAvailable.put(supplier, Boolean.TRUE); } } } } mutableOrderInfo.setMultipleDelivery(multi); mutableOrderInfo.setMultipleDeliveryAvailable(multiAvailable); if (customerOrder.getBillingAddressDetails() != null) { mutableOrderInfo.setBillingAddressId(customerOrder.getBillingAddressDetails().getAddressId()); mutableShoppingContext.setCountryCode(customerOrder.getBillingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getBillingAddressDetails().getStateCode()); mutableOrderInfo.setBillingAddressNotRequired(false); } else { mutableOrderInfo.setBillingAddressNotRequired(true); } if (customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setDeliveryAddressId(customerOrder.getShippingAddressDetails().getAddressId()); if (mutableShoppingContext.getCountryCode() == null) { mutableShoppingContext.setCountryCode(customerOrder.getShippingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getShippingAddressDetails().getStateCode()); } mutableOrderInfo.setDeliveryAddressNotRequired(false); } else { mutableOrderInfo.setDeliveryAddressNotRequired(true); } if (customerOrder.getBillingAddressDetails() != null && customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setSeparateBillingAddress(!customerOrder.getBillingAddress().equals(customerOrder.getShippingAddress())); } else { mutableOrderInfo.setSeparateBillingAddress(false); } mutableOrderInfo.setPaymentGatewayLabel(customerOrder.getPgLabel()); mutableShoppingContext.setCustomerEmail(customerOrder.getEmail()); final Shop configShop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster() : customerOrder.getShop(); mutableShoppingContext.setCustomerName(formatNameFor(customerOrder, configShop)); final List<String> customerShops = new ArrayList<>(); customerShops.add(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShops(customerShops); if (customerOrder.getShop().getMaster() != null) { mutableShoppingContext.setShopId(customerOrder.getShop().getMaster().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getMaster().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } else { mutableShoppingContext.setShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } mutableShoppingContext.setResolvedIp(customerOrder.getOrderIp()); copyOrderCustomAttributes(shoppingCart, customerOrder.getAllValues()); shoppingCart.recalculate(); shoppingCart.markDirty(); return shoppingCart; } }
OrderDisassemblerImpl implements OrderDisassembler { @Override public ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled) throws OrderAssemblyException { final ShoppingCartImpl shoppingCart = new ShoppingCartImpl(); shoppingCart.setPromotionsDisabled(promotionsDisabled); shoppingCart.setOrdernum(customerOrder.getOrdernum()); shoppingCart.initialise(amountCalculationStrategy); if (CollectionUtils.isEmpty(customerOrder.getDelivery())) { for (CustomerOrderDet orderDet : customerOrder.getOrderDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } else { for (CustomerOrderDelivery delivery : customerOrder.getDelivery()) { for (CustomerOrderDeliveryDet orderDet : delivery.getDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } } for(PromotionCouponUsage coupons : customerOrder.getCoupons()) { shoppingCart.addCoupon(coupons.getCouponCode()); } shoppingCart.setCurrentLocale(customerOrder.getLocale()); shoppingCart.setCurrencyCode(customerOrder.getCurrency()); MutableOrderInfo mutableOrderInfo = shoppingCart.getOrderInfo(); MutableShoppingContext mutableShoppingContext = shoppingCart.getShoppingContext(); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF, customerOrder.getB2bRef()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID, customerOrder.getB2bEmployeeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID, customerOrder.getB2bChargeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER, String.valueOf(customerOrder.isB2bRequireApprove())); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_BY, customerOrder.getB2bApprovedBy()); if (customerOrder.getB2bApprovedBy() != null) { mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_DATE, DateUtils.formatSDT(customerOrder.getB2bApprovedDate())); } mutableOrderInfo.setOrderMessage(customerOrder.getOrderMessage()); final Collection<CustomerOrderDelivery> deliveries = customerOrder.getDelivery(); final Map<String, Integer> noOfStdDeliveriesBySupplier = new HashMap<>(); boolean multi = false; final Map<String, Boolean> multiAvailable = new HashMap<>(); if (CollectionUtils.isNotEmpty(deliveries)) { for (final CustomerOrderDelivery delivery : deliveries) { final CartItem first = CollectionUtils.isNotEmpty(delivery.getDetail()) ? delivery.getDetail().iterator().next() : null; final String supplier = first != null && first.getSupplierCode() != null ? first.getSupplierCode() : ""; mutableOrderInfo.putCarrierSlaId(supplier, delivery.getCarrierSla().getCarrierslaId()); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(delivery.getDeliveryGroup())) { Integer count = noOfStdDeliveriesBySupplier.get(supplier); if (count == null) { noOfStdDeliveriesBySupplier.put(supplier, 1); multiAvailable.put(supplier, Boolean.FALSE); } else { noOfStdDeliveriesBySupplier.put(supplier, count + 1); multi = true; multiAvailable.put(supplier, Boolean.TRUE); } } } } mutableOrderInfo.setMultipleDelivery(multi); mutableOrderInfo.setMultipleDeliveryAvailable(multiAvailable); if (customerOrder.getBillingAddressDetails() != null) { mutableOrderInfo.setBillingAddressId(customerOrder.getBillingAddressDetails().getAddressId()); mutableShoppingContext.setCountryCode(customerOrder.getBillingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getBillingAddressDetails().getStateCode()); mutableOrderInfo.setBillingAddressNotRequired(false); } else { mutableOrderInfo.setBillingAddressNotRequired(true); } if (customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setDeliveryAddressId(customerOrder.getShippingAddressDetails().getAddressId()); if (mutableShoppingContext.getCountryCode() == null) { mutableShoppingContext.setCountryCode(customerOrder.getShippingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getShippingAddressDetails().getStateCode()); } mutableOrderInfo.setDeliveryAddressNotRequired(false); } else { mutableOrderInfo.setDeliveryAddressNotRequired(true); } if (customerOrder.getBillingAddressDetails() != null && customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setSeparateBillingAddress(!customerOrder.getBillingAddress().equals(customerOrder.getShippingAddress())); } else { mutableOrderInfo.setSeparateBillingAddress(false); } mutableOrderInfo.setPaymentGatewayLabel(customerOrder.getPgLabel()); mutableShoppingContext.setCustomerEmail(customerOrder.getEmail()); final Shop configShop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster() : customerOrder.getShop(); mutableShoppingContext.setCustomerName(formatNameFor(customerOrder, configShop)); final List<String> customerShops = new ArrayList<>(); customerShops.add(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShops(customerShops); if (customerOrder.getShop().getMaster() != null) { mutableShoppingContext.setShopId(customerOrder.getShop().getMaster().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getMaster().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } else { mutableShoppingContext.setShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } mutableShoppingContext.setResolvedIp(customerOrder.getOrderIp()); copyOrderCustomAttributes(shoppingCart, customerOrder.getAllValues()); shoppingCart.recalculate(); shoppingCart.markDirty(); return shoppingCart; } OrderDisassemblerImpl(final AmountCalculationStrategy amountCalculationStrategy,
                                 final CustomerService customerService); }
OrderDisassemblerImpl implements OrderDisassembler { @Override public ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled) throws OrderAssemblyException { final ShoppingCartImpl shoppingCart = new ShoppingCartImpl(); shoppingCart.setPromotionsDisabled(promotionsDisabled); shoppingCart.setOrdernum(customerOrder.getOrdernum()); shoppingCart.initialise(amountCalculationStrategy); if (CollectionUtils.isEmpty(customerOrder.getDelivery())) { for (CustomerOrderDet orderDet : customerOrder.getOrderDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } else { for (CustomerOrderDelivery delivery : customerOrder.getDelivery()) { for (CustomerOrderDeliveryDet orderDet : delivery.getDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } } for(PromotionCouponUsage coupons : customerOrder.getCoupons()) { shoppingCart.addCoupon(coupons.getCouponCode()); } shoppingCart.setCurrentLocale(customerOrder.getLocale()); shoppingCart.setCurrencyCode(customerOrder.getCurrency()); MutableOrderInfo mutableOrderInfo = shoppingCart.getOrderInfo(); MutableShoppingContext mutableShoppingContext = shoppingCart.getShoppingContext(); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF, customerOrder.getB2bRef()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID, customerOrder.getB2bEmployeeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID, customerOrder.getB2bChargeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER, String.valueOf(customerOrder.isB2bRequireApprove())); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_BY, customerOrder.getB2bApprovedBy()); if (customerOrder.getB2bApprovedBy() != null) { mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_DATE, DateUtils.formatSDT(customerOrder.getB2bApprovedDate())); } mutableOrderInfo.setOrderMessage(customerOrder.getOrderMessage()); final Collection<CustomerOrderDelivery> deliveries = customerOrder.getDelivery(); final Map<String, Integer> noOfStdDeliveriesBySupplier = new HashMap<>(); boolean multi = false; final Map<String, Boolean> multiAvailable = new HashMap<>(); if (CollectionUtils.isNotEmpty(deliveries)) { for (final CustomerOrderDelivery delivery : deliveries) { final CartItem first = CollectionUtils.isNotEmpty(delivery.getDetail()) ? delivery.getDetail().iterator().next() : null; final String supplier = first != null && first.getSupplierCode() != null ? first.getSupplierCode() : ""; mutableOrderInfo.putCarrierSlaId(supplier, delivery.getCarrierSla().getCarrierslaId()); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(delivery.getDeliveryGroup())) { Integer count = noOfStdDeliveriesBySupplier.get(supplier); if (count == null) { noOfStdDeliveriesBySupplier.put(supplier, 1); multiAvailable.put(supplier, Boolean.FALSE); } else { noOfStdDeliveriesBySupplier.put(supplier, count + 1); multi = true; multiAvailable.put(supplier, Boolean.TRUE); } } } } mutableOrderInfo.setMultipleDelivery(multi); mutableOrderInfo.setMultipleDeliveryAvailable(multiAvailable); if (customerOrder.getBillingAddressDetails() != null) { mutableOrderInfo.setBillingAddressId(customerOrder.getBillingAddressDetails().getAddressId()); mutableShoppingContext.setCountryCode(customerOrder.getBillingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getBillingAddressDetails().getStateCode()); mutableOrderInfo.setBillingAddressNotRequired(false); } else { mutableOrderInfo.setBillingAddressNotRequired(true); } if (customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setDeliveryAddressId(customerOrder.getShippingAddressDetails().getAddressId()); if (mutableShoppingContext.getCountryCode() == null) { mutableShoppingContext.setCountryCode(customerOrder.getShippingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getShippingAddressDetails().getStateCode()); } mutableOrderInfo.setDeliveryAddressNotRequired(false); } else { mutableOrderInfo.setDeliveryAddressNotRequired(true); } if (customerOrder.getBillingAddressDetails() != null && customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setSeparateBillingAddress(!customerOrder.getBillingAddress().equals(customerOrder.getShippingAddress())); } else { mutableOrderInfo.setSeparateBillingAddress(false); } mutableOrderInfo.setPaymentGatewayLabel(customerOrder.getPgLabel()); mutableShoppingContext.setCustomerEmail(customerOrder.getEmail()); final Shop configShop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster() : customerOrder.getShop(); mutableShoppingContext.setCustomerName(formatNameFor(customerOrder, configShop)); final List<String> customerShops = new ArrayList<>(); customerShops.add(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShops(customerShops); if (customerOrder.getShop().getMaster() != null) { mutableShoppingContext.setShopId(customerOrder.getShop().getMaster().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getMaster().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } else { mutableShoppingContext.setShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } mutableShoppingContext.setResolvedIp(customerOrder.getOrderIp()); copyOrderCustomAttributes(shoppingCart, customerOrder.getAllValues()); shoppingCart.recalculate(); shoppingCart.markDirty(); return shoppingCart; } OrderDisassemblerImpl(final AmountCalculationStrategy amountCalculationStrategy,
                                 final CustomerService customerService); @Override ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled); }
OrderDisassemblerImpl implements OrderDisassembler { @Override public ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled) throws OrderAssemblyException { final ShoppingCartImpl shoppingCart = new ShoppingCartImpl(); shoppingCart.setPromotionsDisabled(promotionsDisabled); shoppingCart.setOrdernum(customerOrder.getOrdernum()); shoppingCart.initialise(amountCalculationStrategy); if (CollectionUtils.isEmpty(customerOrder.getDelivery())) { for (CustomerOrderDet orderDet : customerOrder.getOrderDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } else { for (CustomerOrderDelivery delivery : customerOrder.getDelivery()) { for (CustomerOrderDeliveryDet orderDet : delivery.getDetail()) { if (orderDet.isGift()) { shoppingCart.addGiftToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getAppliedPromo()); shoppingCart.setGiftPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); shoppingCart.setGiftDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } else { shoppingCart.addProductSkuToCart(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getProductName(), orderDet.getQty(), orderDet.getItemGroup(), orderDet.isConfigurable(), orderDet.isNotSoldSeparately()); shoppingCart.setProductSkuPrice(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getSalePrice(), orderDet.getListPrice()); if (orderDet.isFixedPrice()) { shoppingCart.setProductSkuOffer(orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getPrice(), orderDet.getAppliedPromo()); } shoppingCart.setProductSkuDeliveryBucket(orderDet.getProductSkuCode(), orderDet.getDeliveryBucket()); } copyLineRemarks(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getB2bRemarks()); copyManagedList(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getValue(AttributeNamesKeys.Cart.ORDER_INFO_ORDER_LINE_MANAGED_LIST)); copyLineCustomAttributes(shoppingCart, orderDet.getSupplierCode(), orderDet.getProductSkuCode(), orderDet.getAllValues()); } } } for(PromotionCouponUsage coupons : customerOrder.getCoupons()) { shoppingCart.addCoupon(coupons.getCouponCode()); } shoppingCart.setCurrentLocale(customerOrder.getLocale()); shoppingCart.setCurrencyCode(customerOrder.getCurrency()); MutableOrderInfo mutableOrderInfo = shoppingCart.getOrderInfo(); MutableShoppingContext mutableShoppingContext = shoppingCart.getShoppingContext(); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF, customerOrder.getB2bRef()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID, customerOrder.getB2bEmployeeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID, customerOrder.getB2bChargeId()); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER, String.valueOf(customerOrder.isB2bRequireApprove())); mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_BY, customerOrder.getB2bApprovedBy()); if (customerOrder.getB2bApprovedBy() != null) { mutableOrderInfo.putDetail(AttributeNamesKeys.Cart.ORDER_INFO_B2B_APPROVED_DATE, DateUtils.formatSDT(customerOrder.getB2bApprovedDate())); } mutableOrderInfo.setOrderMessage(customerOrder.getOrderMessage()); final Collection<CustomerOrderDelivery> deliveries = customerOrder.getDelivery(); final Map<String, Integer> noOfStdDeliveriesBySupplier = new HashMap<>(); boolean multi = false; final Map<String, Boolean> multiAvailable = new HashMap<>(); if (CollectionUtils.isNotEmpty(deliveries)) { for (final CustomerOrderDelivery delivery : deliveries) { final CartItem first = CollectionUtils.isNotEmpty(delivery.getDetail()) ? delivery.getDetail().iterator().next() : null; final String supplier = first != null && first.getSupplierCode() != null ? first.getSupplierCode() : ""; mutableOrderInfo.putCarrierSlaId(supplier, delivery.getCarrierSla().getCarrierslaId()); if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(delivery.getDeliveryGroup())) { Integer count = noOfStdDeliveriesBySupplier.get(supplier); if (count == null) { noOfStdDeliveriesBySupplier.put(supplier, 1); multiAvailable.put(supplier, Boolean.FALSE); } else { noOfStdDeliveriesBySupplier.put(supplier, count + 1); multi = true; multiAvailable.put(supplier, Boolean.TRUE); } } } } mutableOrderInfo.setMultipleDelivery(multi); mutableOrderInfo.setMultipleDeliveryAvailable(multiAvailable); if (customerOrder.getBillingAddressDetails() != null) { mutableOrderInfo.setBillingAddressId(customerOrder.getBillingAddressDetails().getAddressId()); mutableShoppingContext.setCountryCode(customerOrder.getBillingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getBillingAddressDetails().getStateCode()); mutableOrderInfo.setBillingAddressNotRequired(false); } else { mutableOrderInfo.setBillingAddressNotRequired(true); } if (customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setDeliveryAddressId(customerOrder.getShippingAddressDetails().getAddressId()); if (mutableShoppingContext.getCountryCode() == null) { mutableShoppingContext.setCountryCode(customerOrder.getShippingAddressDetails().getCountryCode()); mutableShoppingContext.setStateCode(customerOrder.getShippingAddressDetails().getStateCode()); } mutableOrderInfo.setDeliveryAddressNotRequired(false); } else { mutableOrderInfo.setDeliveryAddressNotRequired(true); } if (customerOrder.getBillingAddressDetails() != null && customerOrder.getShippingAddressDetails() != null) { mutableOrderInfo.setSeparateBillingAddress(!customerOrder.getBillingAddress().equals(customerOrder.getShippingAddress())); } else { mutableOrderInfo.setSeparateBillingAddress(false); } mutableOrderInfo.setPaymentGatewayLabel(customerOrder.getPgLabel()); mutableShoppingContext.setCustomerEmail(customerOrder.getEmail()); final Shop configShop = customerOrder.getShop().getMaster() != null ? customerOrder.getShop().getMaster() : customerOrder.getShop(); mutableShoppingContext.setCustomerName(formatNameFor(customerOrder, configShop)); final List<String> customerShops = new ArrayList<>(); customerShops.add(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShops(customerShops); if (customerOrder.getShop().getMaster() != null) { mutableShoppingContext.setShopId(customerOrder.getShop().getMaster().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getMaster().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } else { mutableShoppingContext.setShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setShopCode(customerOrder.getShop().getCode()); mutableShoppingContext.setCustomerShopId(customerOrder.getShop().getShopId()); mutableShoppingContext.setCustomerShopCode(customerOrder.getShop().getCode()); } mutableShoppingContext.setResolvedIp(customerOrder.getOrderIp()); copyOrderCustomAttributes(shoppingCart, customerOrder.getAllValues()); shoppingCart.recalculate(); shoppingCart.markDirty(); return shoppingCart; } OrderDisassemblerImpl(final AmountCalculationStrategy amountCalculationStrategy,
                                 final CustomerService customerService); @Override ShoppingCart assembleShoppingCart(final CustomerOrder customerOrder, final boolean promotionsDisabled);  }