📄 shoppingcartservices.java
字号:
cart.addPayment(paymentId); Debug.log("Added Payment: " + paymentId + " / [no max]", module); } } } else { Debug.log("No payment preferences found for order #" + orderId, module); } List orderItems = orh.getOrderItems(); long nextItemSeq = 0; if (orderItems != null) { Iterator i = orderItems.iterator(); while (i.hasNext()) { GenericValue item = (GenericValue) i.next(); // get the next item sequence id String orderItemSeqId = item.getString("orderItemSeqId"); try { long seq = Long.parseLong(orderItemSeqId); if (seq > nextItemSeq) { nextItemSeq = seq; } } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } // do not include PROMO items if (item.get("isPromo") != null && "Y".equals(item.getString("isPromo"))) { continue; } // not a promo item; go ahead and add it in Double amount = item.getDouble("selectedAmount"); if (amount == null) { amount = new Double(0); } Double quantity = OrderReadHelper.getOrderItemQuantity(item); if (quantity == null) { quantity = new Double(0); } int itemIndex = -1; if (item.get("productId") == null) { // non-product item String itemType = item.getString("orderItemTypeId"); String desc = item.getString("itemDescription"); try { itemIndex = cart.addNonProductItem(itemType, desc, null, 0.00, quantity.doubleValue(), null, null, dispatcher); } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } } else { // product item String prodCatalogId = item.getString("prodCatalogId"); String productId = item.getString("productId"); try { itemIndex = cart.addItemToEnd(productId, amount.doubleValue(), quantity.doubleValue(), null, null, prodCatalogId, dispatcher); } catch (ItemNotFoundException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } } // flag the item w/ the orderItemSeqId so we can reference it ShoppingCartItem cartItem = cart.findCartItem(itemIndex); cartItem.setOrderItemSeqId(item.getString("orderItemSeqId")); // attach addition item information cartItem.setStatusId(item.getString("statusId")); cartItem.setItemType(item.getString("orderItemTypeId")); cartItem.setItemComment(item.getString("comments")); cartItem.setQuoteId(item.getString("quoteId")); cartItem.setQuoteItemSeqId(item.getString("quoteItemSeqId")); cartItem.setProductCategoryId(item.getString("productCategoryId")); cartItem.setDesiredDeliveryDate(item.getTimestamp("estimatedDeliveryDate")); cartItem.setShipBeforeDate(item.getTimestamp("shipBeforeDate")); cartItem.setShipAfterDate(item.getTimestamp("shipAfterDate")); cartItem.setShoppingList(item.getString("shoppingListId"), item.getString("shoppingListItemSeqId")); cartItem.setIsModifiedPrice("Y".equals(item.getString("isModifiedPrice"))); if(cartItem.getIsModifiedPrice()) cartItem.setBasePrice(item.getDouble("unitPrice").doubleValue()); // set the PO number on the cart cart.setPoNumber(item.getString("correspondingPoId")); // set the item's ship group info List shipGroups = orh.getOrderItemShipGroupAssocs(item); for (int g = 0; g < shipGroups.size(); g++) { GenericValue sgAssoc = (GenericValue) shipGroups.get(g); Double shipGroupQty = OrderReadHelper.getOrderItemShipGroupQuantity(sgAssoc); if (shipGroupQty == null) { shipGroupQty = new Double(0); } GenericValue sg = null; try { sg = sgAssoc.getRelatedOne("OrderItemShipGroup"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } cart.setShipAfterDate(g, sg.getTimestamp("shipAfterDate")); cart.setShipBeforeDate(g, sg.getTimestamp("shipByDate")); cart.setShipmentMethodTypeId(g, sg.getString("shipmentMethodTypeId")); cart.setCarrierPartyId(g, sg.getString("carrierPartyId")); cart.setMaySplit(g, sg.getBoolean("maySplit")); cart.setGiftMessage(g, sg.getString("giftMessage")); cart.setShippingContactMechId(g, sg.getString("contactMechId")); cart.setShippingInstructions(g, sg.getString("shippingInstructions")); cart.setItemShipGroupQty(itemIndex, shipGroupQty.doubleValue(), g); } } // set the item seq in the cart if (nextItemSeq > 0) { try { cart.setNextItemSeq(nextItemSeq); } catch (GeneralException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } } } Map result = ServiceUtil.returnSuccess(); result.put("shoppingCart", cart); return result; } public static Map loadCartFromQuote(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); String quoteId = (String) context.get("quoteId"); String applyQuoteAdjustmentsString = (String) context.get("applyQuoteAdjustments"); Locale locale = (Locale) context.get("locale"); boolean applyQuoteAdjustments = applyQuoteAdjustmentsString == null || "true".equals(applyQuoteAdjustmentsString); // get the quote header GenericValue quote = null; try { quote = delegator.findByPrimaryKey("Quote", UtilMisc.toMap("quoteId", quoteId)); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } // initial require cart info String productStoreId = quote.getString("productStoreId"); String currency = quote.getString("currencyUomId"); // create the cart ShoppingCart cart = new ShoppingCart(delegator, productStoreId, locale, currency); try { cart.setUserLogin(userLogin, dispatcher); } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } cart.setQuoteId(quoteId); List quoteItems = null; List quoteAdjs = null; List quoteRoles = null; List quoteAttributes = null; try { quoteItems = quote.getRelated("QuoteItem"); quoteAdjs = quote.getRelated("QuoteAdjustment"); quoteRoles = quote.getRelated("QuoteRole"); quoteAttributes = quote.getRelated("QuoteAttribute"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } // set the role information cart.setOrderPartyId(quote.getString("partyId")); if (quoteRoles != null) { Iterator quoteRolesIt = quoteRoles.iterator(); while (quoteRolesIt.hasNext()) { GenericValue quoteRole = (GenericValue)quoteRolesIt.next(); String quoteRoleTypeId = quoteRole.getString("roleTypeId"); String quoteRolePartyId = quoteRole.getString("partyId"); if ("PLACING_CUSTOMER".equals(quoteRoleTypeId)) { cart.setPlacingCustomerPartyId(quoteRolePartyId); } else if ("BILL_TO_CUSTOMER".equals(quoteRoleTypeId)) { cart.setBillToCustomerPartyId(quoteRolePartyId); } else if ("SHIP_TO_CUSTOMER".equals(quoteRoleTypeId)) { cart.setShipToCustomerPartyId(quoteRolePartyId); } else if ("END_USER_CUSTOMER".equals(quoteRoleTypeId)) { cart.setEndUserCustomerPartyId(quoteRolePartyId); } else { cart.addAdditionalPartyRole(quoteRolePartyId, quoteRoleTypeId); } } } // set the attribute information if (quoteAttributes != null) { Iterator quoteAttributesIt = quoteAttributes.iterator(); while (quoteAttributesIt.hasNext()) { GenericValue quoteAttribute = (GenericValue)quoteAttributesIt.next(); cart.setOrderAttribute(quoteAttribute.getString("attrName"), quoteAttribute.getString("attrValue")); } } // Convert the quote adjustment to order header adjustments and // put them in a map: the key/values pairs are quoteItemSeqId/List of adjs Map orderAdjsMap = new HashMap(); Iterator quoteAdjsIter = quoteAdjs.iterator(); while (quoteAdjsIter.hasNext()) { GenericValue quoteAdj = (GenericValue)quoteAdjsIter.next(); List orderAdjs = (List)orderAdjsMap.get(quoteAdj.get("quoteItemSeqId")); if (orderAdjs == null) { orderAdjs = new LinkedList(); orderAdjsMap.put(quoteAdj.get("quoteItemSeqId"), orderAdjs); } // convert quote adjustments to order adjustments GenericValue orderAdj = delegator.makeValue("OrderAdjustment", null); orderAdj.put("orderAdjustmentId", quoteAdj.get("quoteAdjustmentId")); orderAdj.put("orderAdjustmentTypeId", quoteAdj.get("quoteAdjustmentTypeId")); orderAdj.put("orderItemSeqId", quoteAdj.get("quoteItemSeqId")); orderAdj.put("comments", quoteAdj.get("comments")); orderAdj.put("description", quoteAdj.get("description")); orderAdj.put("amount", quoteAdj.get("amount")); orderAdj.put("productPromoId", quoteAdj.get("productPromoId")); orderAdj.put("productPromoRuleId", quoteAdj.get("productPromoRuleId")); orderAdj.put("productPromoActionSeqId", quoteAdj.get("productPromoActionSeqId")); orderAdj.put("productFeatureId", quoteAdj.get("productFeatureId")); orderAdj.put("correspondingProductId", quoteAdj.get("correspondingProductId")); orderAdj.put("sourceReferenceId", quoteAdj.get("sourceReferenceId")); orderAdj.put("sourcePercentage", quoteAdj.get("sourcePercentage")); orderAdj.put("customerReferenceId", quoteAdj.get("customerReferenceId"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -