Author: jacopoc
Date: Wed Nov 21 10:10:04 2007 New Revision: 597166 URL: http://svn.apache.org/viewvc?rev=597166&view=rev Log: Implemented new signature (that accepts a parameters Map instead of an HttpServletRequest) for the util method: makeParamMapWithPrefix. Added code to the ShoppingCartHelper..addToCart method to prepare a map of additiona features for the cart (if additional features are selected during order entry). Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=597166&r1=597165&r2=597166&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Wed Nov 21 10:10:04 2007 @@ -40,6 +40,8 @@ import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; +import javolution.util.FastMap; + /** * A facade over the * {@link org.ofbiz.order.shoppingcart.ShoppingCart ShoppingCart} @@ -174,12 +176,35 @@ } + // Get the additional features selected for the product (if any) + Map selectedFeatures = UtilHttp.makeParamMapWithPrefix(context, null, "FT", null); + Iterator selectedFeaturesTypes = selectedFeatures.keySet().iterator(); + Map additionalFeaturesMap = FastMap.newInstance(); + while (selectedFeaturesTypes.hasNext()) { + String selectedFeatureType = (String)selectedFeaturesTypes.next(); + String selectedFeatureValue = (String)selectedFeatures.get(selectedFeatureType); + if (UtilValidate.isNotEmpty(selectedFeatureValue)) { + GenericValue productFeatureAndAppl = null; + try { + productFeatureAndAppl = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", + UtilMisc.toMap("productId", productId, + "productFeatureId", selectedFeatureValue)))); + } catch (GenericEntityException gee) { + Debug.logError(gee, module); + } + if (UtilValidate.isNotEmpty(productFeatureAndAppl)) { + productFeatureAndAppl.set("productFeatureApplTypeId", "STANDARD_FEATURE"); + } + additionalFeaturesMap.put(selectedFeatureType, productFeatureAndAppl); + } + } + // add or increase the item to the cart try { int itemId = -1; if (productId != null) { itemId = cart.addOrIncreaseItem(productId, amount, quantity, reservStart, reservLength, - reservPersons, shipBeforeDate, shipAfterDate, null, attributes, + reservPersons, shipBeforeDate, shipAfterDate, additionalFeaturesMap, attributes, catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher); } else { itemId = cart.addNonProductItem(itemType, itemDescription, productCategoryId, price, quantity, attributes, catalogId, itemGroupNumber, dispatcher); Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=597166&r1=597165&r2=597166&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Wed Nov 21 10:10:04 2007 @@ -289,20 +289,24 @@ } public static Map<String, Object> makeParamMapWithPrefix(HttpServletRequest request, Map<String, Object> additionalFields, String prefix, String suffix) { + return makeParamMapWithPrefix(getParameterMap(request), additionalFields, prefix, suffix); + } + + public static Map<String, Object> makeParamMapWithPrefix(Map<String, Object> context, Map<String, Object> additionalFields, String prefix, String suffix) { Map<String, Object> paramMap = new HashMap<String, Object>(); - Enumeration parameterNames = request.getParameterNames(); - while (parameterNames.hasMoreElements()) { - String parameterName = (String) parameterNames.nextElement(); + Iterator parameterNames = context.keySet().iterator(); + while (parameterNames.hasNext()) { + String parameterName = (String) parameterNames.next(); if (parameterName.startsWith(prefix)) { if (suffix != null && suffix.length() > 0) { if (parameterName.endsWith(suffix)) { String key = parameterName.substring(prefix.length(), parameterName.length() - (suffix.length())); - String value = request.getParameter(parameterName); + String value = (String)context.get(parameterName); paramMap.put(key, value); } } else { String key = parameterName.substring(prefix.length()); - String value = request.getParameter(parameterName); + String value = (String)context.get(parameterName); paramMap.put(key, value); } } |
Free forum by Nabble | Edit this page |