📄 shoppingcartevents.java
字号:
} } } if (hasPermission) { cart = ShoppingCartEvents.getCartObject(request, null, productStore.getString("defaultCurrencyUomId")); } else { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToTakeOrdersForThisStore", locale)); cart.clear(); session.removeAttribute("orderMode"); return "error"; } cart.setProductStoreId(productStoreId); } else { cart.setProductStoreId(null); } } if ("SALES_ORDER".equals(cart.getOrderType()) && UtilValidate.isEmpty(cart.getProductStoreId())) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderAProductStoreMustBeSelectedForASalesOrder", locale)); cart.clear(); session.removeAttribute("orderMode"); return "error"; } String salesChannelEnumId = request.getParameter("salesChannelEnumId"); if (UtilValidate.isNotEmpty(salesChannelEnumId)) { cart.setChannelType(salesChannelEnumId); } // set party info String partyId = request.getParameter("supplierPartyId"); if (!UtilValidate.isEmpty(request.getParameter("partyId"))) { partyId = request.getParameter("partyId"); } String userLoginId = request.getParameter("userLoginId"); if (partyId != null || userLoginId != null) { if ((partyId == null || partyId.length() == 0) && userLoginId != null && userLoginId.length() > 0) { GenericValue thisUserLogin = null; try { thisUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); } catch(GenericEntityException gee) { // } if (thisUserLogin != null) { partyId = thisUserLogin.getString("partyId"); } else { partyId = userLoginId; } } if (partyId != null && partyId.length() > 0) { GenericValue thisParty = null; try{ thisParty = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId)); } catch(GenericEntityException gee) { // } if (thisParty == null) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderCouldNotLocateTheSelectedParty", locale)); return "error"; } else { cart.setOrderPartyId(partyId); } } else if (partyId != null && partyId.length() == 0) { cart.setOrderPartyId("_NA_"); partyId = null; } } else { partyId = cart.getPartyId(); if (partyId != null && partyId.equals("_NA_")) partyId = null; } return "success"; } /** Route order entry **/ public static String routeOrderEntry(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); // if the order mode is not set in the attributes, then order entry has not been initialized if (session.getAttribute("orderMode") == null) { return "init"; } // if the request is coming from the init page, then orderMode will be in the request parameters if (request.getParameter("orderMode") != null) { return "agreements"; // next page after init is always agreements } // orderMode is set and there is an order in progress, so go straight to the cart return "cart"; } public static String doManualPromotions(HttpServletRequest request, HttpServletResponse response) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); ShoppingCart cart = getCartObject(request); List manualPromotions = new LinkedList(); // iterate through the context and find all keys that start with "productPromoId_" Map context = UtilHttp.getParameterMap(request); String keyPrefix = "productPromoId_"; for (int i = 1; i <= 50; i++) { String productPromoId = (String)context.get(keyPrefix + i); if (UtilValidate.isNotEmpty(productPromoId)) { try { GenericValue promo = delegator.findByPrimaryKey("ProductPromo", UtilMisc.toMap("productPromoId", productPromoId)); if (promo != null) { manualPromotions.add(promo); } } catch(GenericEntityException gee) { request.setAttribute("_ERROR_MESSAGE_", gee.getMessage()); return "error"; } } else { break; } } ProductPromoWorker.doPromotions(cart, manualPromotions, dispatcher); return "success"; } public static String bulkAddProducts(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); ShoppingCart cart = ShoppingCartEvents.getCartObject(request); ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart); String controlDirective = null; Map result = null; String productId = null; String productCategoryId = null; String quantityStr = null; String itemDesiredDeliveryDateStr = null; double quantity = 0; String catalogId = CatalogWorker.getCurrentCatalogId(request); String rowCountField = null; int rowCount = 0; // number of rows of products to add String DELIMITER = "_o_"; // delimiter, separating field from row number // Get the parameters as a MAP, remove the productId and quantity params. Map paramMap = UtilHttp.getParameterMap(request); // Get shoppingList info if passed. I think there can only be one shoppingList per request String shoppingListId = request.getParameter("shoppingListId"); String shoppingListItemSeqId = request.getParameter("shoppingListItemSeqId"); // try to get the rowCount information passed in from request if (paramMap.containsKey("_rowCount")) { rowCountField = (String) paramMap.remove("_rowCount"); } else { Debug.logWarning("No _rowCount was passed in", ShoppingCartEvents.module); } try { rowCount = Integer.parseInt(rowCountField); } catch (NumberFormatException e) { Debug.logWarning("Invalid value for rowCount =" + rowCountField, module); } if (rowCount < 1) { Debug.logWarning("No rows to process, as rowCount = " + rowCount, module); } else { for (int i = 0; i < rowCount; i++) { controlDirective = null; // re-initialize each time String thisSuffix = DELIMITER + i; // current suffix after each field id // get the productId if (paramMap.containsKey("productId" + thisSuffix)) { productId = (String) paramMap.remove("productId" + thisSuffix); } if (paramMap.containsKey("quantity" + thisSuffix)) { quantityStr = (String) paramMap.remove("quantity" + thisSuffix); } if ((quantityStr == null) || (quantityStr.equals(""))){ // otherwise, every empty value causes an exception and makes the log ugly quantityStr = "0"; // default quantity is 0, so without a quantity input, this field will not be added } // parse the quantity try { quantity = NumberFormat.getNumberInstance().parse(quantityStr).doubleValue(); } catch (Exception e) { Debug.logWarning(e, "Problems parsing quantity string: " + quantityStr, module); quantity = 0; } // get the selected amount String selectedAmountStr = "0.00"; if (paramMap.containsKey("amount" + thisSuffix)) { selectedAmountStr = (String) paramMap.remove("amount" + thisSuffix); } // parse the amount double amount = 0.00; if (selectedAmountStr != null && selectedAmountStr.length() > 0) { try { amount = NumberFormat.getNumberInstance().parse(selectedAmountStr).doubleValue(); } catch (Exception e) { Debug.logWarning(e, "Problem parsing amount string: " + selectedAmountStr, module); amount = 0.00; } } if (paramMap.containsKey("itemDesiredDeliveryDate" + thisSuffix)) { itemDesiredDeliveryDateStr = (String) paramMap.remove("itemDesiredDeliveryDate" + thisSuffix); } Map itemAttributes = UtilMisc.toMap("itemDesiredDeliveryDate", itemDesiredDeliveryDateStr); if (quantity > 0) { Debug.logInfo("Attempting to add to cart with productId = " + productId + ", categoryId = " + productCategoryId + " and quantity = " + quantity, module); result = cartHelper.addToCart(catalogId, shoppingListId, shoppingListItemSeqId, productId, productCategoryId, "", "", 0.00, amount, quantity, null, 0.00, 0.00, null, null, null, itemAttributes); // no values for itemType, itemDescription, price, and paramMap (a context for adding attributes) controlDirective = processResult(result, request); if (controlDirective.equals(ERROR)){ // if the add to cart failed, then get out of this loop right away return "error"; } } } } // Determine where to send the browser return cart.viewCartOnAdd() ? "viewcart" : "success"; } // request method for setting the currency, agreement and shipment dates at once public static String setOrderCurrencyAgreementShipDates(HttpServletRequest request, HttpServletResponse response) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); ShoppingCart cart = getCartObject(request); ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart); String agreementId = (String) request.getParameter("agreementId"); String currencyUomId = (String) request.getParameter("currencyUomId"); String shipBeforeDateStr = (String) request.getParameter("shipBeforeDate"); String shipAfterDateStr = (String) request.getParameter("shipAfterDate"); Map result = null; // set the agreement if specified otherwise set the currency if (agreementId != null && agreementId.length() > 0) { result = cartHelper.selectAgreement(agreementId); } else { result = cartHelper.setCurrency(currencyUomId); } if (ServiceUtil.isError(result)) { request.setAttribute("_ERROR_MESSAGE_", ServiceUtil.getErrorMessage(result)); return "error"; } // set the default ship before and after dates if supplied try { if (UtilValidate.isNotEmpty(shipBeforeDateStr)) { if (shipBeforeDateStr.length() == 10) shipBeforeDateStr += " 00:00:00.000"; cart.setDefaultShipBeforeDate(java.sql.Timestamp.valueOf(shipBeforeDateStr)); } if (UtilValidate.isNotEmpty(shipAfterDateStr)) { if (shipAfterDateStr.length() == 10) shipAfterDateStr += " 00:00:00.000"; cart.setDefaultShipAfterDate(java.sql.Timestamp.valueOf(shipAfterDateStr)); } } catch (IllegalArgumentException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } return "success"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -