📄 shoppingcarthelper.java
字号:
} catch (NumberFormatException nfe) { Debug.logWarning(nfe, UtilProperties.getMessage(resource_error,"OrderCaughtNumberFormatExceptionOnCartUpdate", cart.getLocale())); } catch (ParseException pe) { Debug.logWarning(pe, UtilProperties.getMessage(resource_error,"OrderCaughtParseExceptionOnCartUpdate", cart.getLocale())); } catch (Exception e) { Debug.logWarning(e, UtilProperties.getMessage(resource_error,"OrderCaughtExceptionOnCartUpdate", cart.getLocale())); } } // else not a parameter we need } // get a list of the items to delete if (removeSelected) { for (int si = 0; si < selectedItems.length; si++) { String indexStr = selectedItems[si]; ShoppingCartItem item = null; try { int index = Integer.parseInt(indexStr); item = this.cart.findCartItem(index); } catch (Exception e) { Debug.logWarning(e, UtilProperties.getMessage(resource_error,"OrderProblemsGettingTheCartItemByIndex", cart.getLocale())); } if (item != null) { deleteList.add(item); } } } Iterator di = deleteList.iterator(); while (di.hasNext()) { ShoppingCartItem item = (ShoppingCartItem) di.next(); int itemIndex = this.cart.getItemIndex(item); if (Debug.infoOn()) Debug.logInfo("Removing item index: " + itemIndex, module); try { this.cart.removeCartItem(itemIndex, dispatcher); } catch (CartItemModifyException e) { result = ServiceUtil.returnError(new Vector()); errorMsgs.add(e.getMessage()); } } if (context.containsKey("alwaysShowcart")) { this.cart.setViewCartOnAdd(true); } else { this.cart.setViewCartOnAdd(false); } // Promotions are run again. ProductPromoWorker.doPromotions(this.cart, dispatcher); if (errorMsgs.size() > 0) { result = ServiceUtil.returnError(errorMsgs); return result; } result = ServiceUtil.returnSuccess(); return result; } /** Empty the shopping cart. */ public boolean clearCart() { this.cart.clear(); return true; } /** Returns the shopping cart this helper is wrapping. */ public ShoppingCart getCartObject() { return this.cart; } public GenericValue getFeatureAppl(String productId, String optionField, String featureId) { if (delegator == null) { throw new IllegalArgumentException("No delegator available to lookup ProductFeature"); } Map fields = UtilMisc.toMap("productId", productId, "productFeatureId", featureId); if (optionField != null) { int featureTypeStartIndex = optionField.indexOf('^') + 1; int featureTypeEndIndex = optionField.lastIndexOf('_'); if (featureTypeStartIndex > 0 && featureTypeEndIndex > 0) { fields.put("productFeatureTypeId", optionField.substring(featureTypeStartIndex, featureTypeEndIndex)); } } GenericValue productFeatureAppl = null; List features = null; try { features = delegator.findByAnd("ProductFeatureAndAppl", fields, UtilMisc.toList("-fromDate")); } catch (GenericEntityException e) { Debug.logError(e, module); return null; } if (features != null) { if (features.size() > 1) { features = EntityUtil.filterByDate(features); } productFeatureAppl = EntityUtil.getFirst(features); } return productFeatureAppl; } public String getRemoveFeatureTypeId(String optionField) { if (optionField != null) { int featureTypeStartIndex = optionField.indexOf('^') + 1; int featureTypeEndIndex = optionField.lastIndexOf('_'); if (featureTypeStartIndex > 0 && featureTypeEndIndex > 0) { return optionField.substring(featureTypeStartIndex, featureTypeEndIndex); } } return null; } /** * Select an agreement * * @param agreementId */ public Map selectAgreement(String agreementId) { ArrayList errorMsgs = new ArrayList(); Map result = null; GenericValue agreement = null; if ((this.delegator == null) || (this.dispatcher == null) || (this.cart == null)) { result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderDispatcherOrDelegatorOrCartArgumentIsNull",this.cart.getLocale())); return result; } if ((agreementId == null) || (agreementId.length() <= 0)) { result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderNoAgreementSpecified",this.cart.getLocale())); return result; } try { agreement = this.delegator.findByPrimaryKeyCache("Agreement",UtilMisc.toMap("agreementId", agreementId)); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCouldNotGetAgreement",UtilMisc.toMap("agreementId",agreementId),this.cart.getLocale()) + UtilProperties.getMessage(resource_error,"OrderError",this.cart.getLocale()) + e.getMessage()); return result; } if (agreement == null) { result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCouldNotGetAgreement",UtilMisc.toMap("agreementId",agreementId),this.cart.getLocale())); } else { // set the agreement id in the cart cart.setAgreementId(agreementId); try { // set the currency based on the pricing agreement List agreementItems = agreement.getRelated("AgreementItem", UtilMisc.toMap("agreementItemTypeId", "AGREEMENT_PRICING_PR"), null); if (agreementItems.size() > 0) { GenericValue agreementItem = (GenericValue) agreementItems.get(0); String currencyUomId = (String) agreementItem.get("currencyUomId"); try { cart.setCurrency(dispatcher,currencyUomId); } catch (CartItemModifyException ex) { result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderSetCurrencyError",this.cart.getLocale()) + ex.getMessage()); return result; } } } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCouldNotGetAgreementItemsThrough",UtilMisc.toMap("agreementId",agreementId),this.cart.getLocale()) + UtilProperties.getMessage(resource_error,"OrderError",this.cart.getLocale()) + e.getMessage()); return result; } try { // clear the existing order terms cart.removeOrderTerms(); // set order terms based on agreement terms List agreementTerms = agreement.getRelated("AgreementTerm"); if (agreementTerms.size() > 0) { for (int i = 0; agreementTerms.size() > i;i++) { GenericValue agreementTerm = (GenericValue) agreementTerms.get(i); String termTypeId = (String) agreementTerm.get("termTypeId"); Double termValue = (Double) agreementTerm.get("termValue"); Long termDays = (Long) agreementTerm.get("termDays"); cart.addOrderTerm(termTypeId, termValue, termDays); } } } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderCouldNotGetAgreementTermsThrough",UtilMisc.toMap("agreementId",agreementId),this.cart.getLocale()) + UtilProperties.getMessage(resource_error,"OrderError",this.cart.getLocale()) + e.getMessage()); return result; } } return result; } public Map setCurrency(String currencyUomId) { Map result = null; try { this.cart.setCurrency(this.dispatcher,currencyUomId); result = ServiceUtil.returnSuccess(); } catch (CartItemModifyException ex) { result = ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"Set currency error",this.cart.getLocale()) + ex.getMessage()); return result; } return result; } public Map addOrderTerm(String termTypeId,Double termValue,Long termDays) { Map result = null; String errMsg = null; this.cart.addOrderTerm(termTypeId,termValue,termDays); result = ServiceUtil.returnSuccess(); return result; } public Map removeOrderTerm(int index) { Map result = null; String errMsg = null; this.cart.removeOrderTerm(index); result = ServiceUtil.returnSuccess(); return result; } /** Get the first SupplierProduct record for productId with matching quantity and currency */ public GenericValue getProductSupplier(String productId, Double quantity, String currencyUomId) { GenericValue productSupplier = null; Map params = UtilMisc.toMap("productId", productId, "partyId", cart.getPartyId(), "currencyUomId", currencyUomId, "quantity", quantity); try { Map result = dispatcher.runSync("getSuppliersForProduct", params); List productSuppliers = (List)result.get("supplierProducts"); if ((productSuppliers != null) && (productSuppliers.size() > 0)) { productSupplier=(GenericValue) productSuppliers.get(0); } } catch (GenericServiceException e) { Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderRunServiceGetSuppliersForProductError", cart.getLocale()) + e.getMessage(), module); } return productSupplier; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -