Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java Sun May 29 11:02:09 2011 @@ -43,7 +43,6 @@ import org.ofbiz.entity.DelegatorFactory import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.product.ProductContentWrapper; import org.ofbiz.webapp.control.ContextFilter; @@ -57,8 +56,6 @@ public class CatalogUrlFilter extends Co public static final String PRODUCT_REQUEST = "product"; public static final String CATEGORY_REQUEST = "category"; - protected static String defaultViewIndex = null; - protected static String defaultViewSize = null; protected static String defaultLocaleString = null; protected static String redirectUrl = null; @@ -105,20 +102,16 @@ public class CatalogUrlFilter extends Co } // set initial parameters - String initDefaultViewIndex = config.getInitParameter("defaultViewIndex"); - String initDefaultViewSize = config.getInitParameter("defaultViewSize"); String initDefaultLocalesString = config.getInitParameter("defaultLocaleString"); String initRedirectUrl = config.getInitParameter("redirectUrl"); - defaultViewIndex = UtilValidate.isNotEmpty(initDefaultViewIndex) ? initDefaultViewIndex : ""; - defaultViewSize = UtilValidate.isNotEmpty(initDefaultViewSize) ? initDefaultViewSize : ""; defaultLocaleString = UtilValidate.isNotEmpty(initDefaultLocalesString) ? initDefaultLocalesString : ""; redirectUrl = UtilValidate.isNotEmpty(initRedirectUrl) ? initRedirectUrl : ""; String pathInfo = httpRequest.getServletPath(); - if (UtilValidate.isNotEmpty(pathInfo)) { List<String> pathElements = StringUtil.split(pathInfo, "/"); String alternativeUrl = pathElements.get(0); + // get web site and default locale string String localeString = null; String webSiteId = WebSiteWorker.getWebSiteId(request); @@ -138,8 +131,8 @@ public class CatalogUrlFilter extends Co } // get view index, view size and view sort from path info - String viewIndex = defaultViewIndex; - String viewSize = defaultViewSize; + String viewIndex = null; + String viewSize = null; String viewSort = null; String searchString = null; @@ -163,38 +156,131 @@ public class CatalogUrlFilter extends Co } } + if (UtilValidate.isNotEmpty(httpRequest.getParameter("viewIndex"))) { + viewIndex = httpRequest.getParameter("viewIndex"); + } + if (UtilValidate.isNotEmpty(httpRequest.getParameter("viewSize"))) { + viewSize = httpRequest.getParameter("viewSize"); + } + if (UtilValidate.isNotEmpty(httpRequest.getParameter("viewSort"))) { + viewSort = httpRequest.getParameter("viewSort"); + } + if (UtilValidate.isNotEmpty(httpRequest.getParameter("searchString"))) { + searchString = httpRequest.getParameter("searchString"); + } + String productId = null; String productCategoryId = null; try { // look for productId - List<EntityCondition> productContentConds = FastList.newInstance(); - productContentConds.add(EntityCondition.makeCondition( - EntityCondition.makeCondition("drObjectInfo", alternativeUrl) - , EntityOperator.OR - , EntityCondition.makeCondition("drObjectInfo", "/" + alternativeUrl))); - productContentConds.add(EntityCondition.makeCondition("localeString", localeString)); - productContentConds.add(EntityCondition.makeCondition("productContentTypeId", "ALTERNATIVE_URL")); - productContentConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productContentInfos = delegator.findList("ProductContentAndInfo", EntityCondition.makeCondition(productContentConds), null, UtilMisc.toList("-fromDate"), null, true); - if (UtilValidate.isNotEmpty(productContentInfos)) { - GenericValue productContentInfo = EntityUtil.getFirst(productContentInfos); - productId = productContentInfo.getString("productId"); + if (alternativeUrl.endsWith("-p")) { + List<EntityCondition> productContentConds = FastList.newInstance(); + productContentConds.add(EntityCondition.makeCondition("productContentTypeId", "ALTERNATIVE_URL")); + productContentConds.add(EntityUtil.getFilterByDateExpr()); + List<GenericValue> productContentInfos = delegator.findList("ProductContentAndInfo", EntityCondition.makeCondition(productContentConds), null, UtilMisc.toList("-fromDate"), null, true); + if (UtilValidate.isNotEmpty(productContentInfos)) { + for(GenericValue productContentInfo : productContentInfos){ + String contentId = (String) productContentInfo.get("contentId"); + List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAndCache("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "drLocaleString", localeString, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT")); + if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ + for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { + GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOneCache("ElectronicText"); + if (UtilValidate.isNotEmpty(ElectronicText)) { + String textData = (String) ElectronicText.get("textData"); + textData = invalidCharacter(textData); + if (alternativeUrl.matches(textData + ".+$")) { + String productIdStr = null; + productIdStr = alternativeUrl.replace(textData + "-", ""); + productIdStr = productIdStr.replace("-p", ""); + String checkProductId = (String) productContentInfo.get("productId"); + if (productIdStr.equalsIgnoreCase(checkProductId)) { + productId = checkProductId; + break; + } + } + } + } + } else { + List<GenericValue> contentDataResourceViews = delegator.findByAndCache("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "statusId", "CTNT_IN_PROGRESS", "drDataResourceTypeId", "ELECTRONIC_TEXT")); + for (GenericValue contentDataResourceView : contentDataResourceViews) { + GenericValue ElectronicText = contentDataResourceView.getRelatedOneCache("ElectronicText"); + if (UtilValidate.isNotEmpty(ElectronicText)) { + String textData = (String) ElectronicText.get("textData"); + if (UtilValidate.isNotEmpty(textData)) { + textData = invalidCharacter(textData); + if (alternativeUrl.matches(textData + ".+$")) { + String productIdStr = null; + productIdStr = alternativeUrl.replace(textData + "-", ""); + productIdStr = productIdStr.replace("-p", ""); + String checkProductId = (String) productContentInfo.get("productId"); + if (productIdStr.equalsIgnoreCase(checkProductId)) { + productId = checkProductId; + break; + } + } + } + } + } + } + } + } } // look for productCategoryId - List<EntityCondition> productCategoryContentConds = FastList.newInstance(); - productCategoryContentConds.add(EntityCondition.makeCondition( - EntityCondition.makeCondition("drObjectInfo", alternativeUrl) - , EntityOperator.OR - , EntityCondition.makeCondition("drObjectInfo", "/" + alternativeUrl))); - productContentConds.add(EntityCondition.makeCondition("localeString", localeString)); - productCategoryContentConds.add(EntityCondition.makeCondition("prodCatContentTypeId", "ALTERNATIVE_URL")); - productCategoryContentConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productCategoryContentInfos = delegator.findList("ProductCategoryContentAndInfo", EntityCondition.makeCondition(productCategoryContentConds), null, UtilMisc.toList("-fromDate"), null, true); - if (UtilValidate.isNotEmpty(productCategoryContentInfos)) { - GenericValue productCategoryContentInfo = EntityUtil.getFirst(productCategoryContentInfos); - productCategoryId = productCategoryContentInfo.getString("productCategoryId"); + if (alternativeUrl.endsWith("-c")) { + List<EntityCondition> productCategoryContentConds = FastList.newInstance(); + productCategoryContentConds.add(EntityCondition.makeCondition("prodCatContentTypeId", "ALTERNATIVE_URL")); + productCategoryContentConds.add(EntityUtil.getFilterByDateExpr()); + List<GenericValue> productCategoryContentInfos = delegator.findList("ProductCategoryContentAndInfo", EntityCondition.makeCondition(productCategoryContentConds), null, UtilMisc.toList("-fromDate"), null, true); + if (UtilValidate.isNotEmpty(productCategoryContentInfos)) { + for(GenericValue productCategoryContentInfo : productCategoryContentInfos){ + String contentId = (String) productCategoryContentInfo.get("contentId"); + List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAndCache("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "drLocaleString", localeString, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT")); + if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ + for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { + GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOneCache("ElectronicText"); + if (UtilValidate.isNotEmpty(ElectronicText)){ + String textData = (String) ElectronicText.get("textData"); + if (UtilValidate.isNotEmpty(textData)) { + textData = invalidCharacter(textData); + if (alternativeUrl.matches(textData + ".+$")) { + String productCategoryStr = null; + productCategoryStr = alternativeUrl.replace(textData + "-", ""); + productCategoryStr = productCategoryStr.replace("-c", ""); + String checkProductCategoryId = (String) productCategoryContentInfo.get("productCategoryId"); + if (productCategoryStr.equalsIgnoreCase(checkProductCategoryId)) { + productCategoryId = checkProductCategoryId; + break; + } + } + } + } + } + } else { + List<GenericValue> contentDataResourceViews = delegator.findByAndCache("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "statusId", "CTNT_IN_PROGRESS", "drDataResourceTypeId", "ELECTRONIC_TEXT")); + for (GenericValue contentDataResourceView : contentDataResourceViews) { + GenericValue ElectronicText = contentDataResourceView.getRelatedOneCache("ElectronicText"); + if (UtilValidate.isNotEmpty(ElectronicText)) { + String textData = (String) ElectronicText.get("textData"); + if (UtilValidate.isNotEmpty(textData)) { + textData = invalidCharacter(textData); + if (alternativeUrl.matches(textData + ".+$")) { + String productCategoryStr = null; + productCategoryStr = alternativeUrl.replace(textData + "-", ""); + productCategoryStr = productCategoryStr.replace("-c", ""); + String checkProductCategoryId = (String) productCategoryContentInfo.get("productCategoryId"); + if (productCategoryStr.equalsIgnoreCase(checkProductCategoryId)) { + productCategoryId = checkProductCategoryId; + break; + } + } + } + } + } + } + } + } } } catch (GenericEntityException e) { Debug.logWarning("Cannot look for product and product category", module); @@ -387,6 +473,7 @@ public class CatalogUrlFilter extends Co public static String makeCategoryUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) { Delegator delegator = (Delegator) request.getAttribute("delegator"); + String url = null; try { GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), true); CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request); @@ -399,7 +486,13 @@ public class CatalogUrlFilter extends Co urlBuilder.append("/"); } // append alternative URL - urlBuilder.append(alternativeUrl); + url = invalidCharacter(alternativeUrl.toString()); + urlBuilder.append(url); + if (UtilValidate.isNotEmpty(productCategoryId)) { + urlBuilder.append("-"); + urlBuilder.append(productCategoryId); + urlBuilder.append("-c"); + } // append view index if (UtilValidate.isNotEmpty(viewIndex)) { if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) { @@ -428,6 +521,10 @@ public class CatalogUrlFilter extends Co } urlBuilder.append("searchString=" + searchString + "&"); } + if (urlBuilder.toString().endsWith("&")) { + return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1); + } + return urlBuilder.toString(); } else { return CatalogUrlServlet.makeCatalogUrl(request, productId, productCategoryId, previousCategoryId); @@ -440,6 +537,7 @@ public class CatalogUrlFilter extends Co public static String makeProductUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId) { Delegator delegator = (Delegator) request.getAttribute("delegator"); + String url = null; try { GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true); ProductContentWrapper wrapper = new ProductContentWrapper(product, request); @@ -451,7 +549,13 @@ public class CatalogUrlFilter extends Co urlBuilder.append("/"); } // append alternative URL - urlBuilder.append(alternativeUrl); + url = invalidCharacter(alternativeUrl.toString()); + urlBuilder.append(url); + if (UtilValidate.isNotEmpty(productId)) { + urlBuilder.append("-"); + urlBuilder.append(productId); + urlBuilder.append("-p"); + } return urlBuilder.toString(); } else { return CatalogUrlServlet.makeCatalogUrl(request, productId, productCategoryId, previousCategoryId); @@ -461,4 +565,82 @@ public class CatalogUrlFilter extends Co return redirectUrl; } } + + public static String invalidCharacter(String str) { + str = str.replace("&", "-"); + str = str.replace("\"", "-"); + str = str.replace("Ã", "-"); + str = str.replace("÷", "-"); + str = str.replace(" ", "-"); + str = str.replace("!", "-"); + str = str.replace("#", "-"); + str = str.replace("$", "-"); + str = str.replace("%", "-"); + str = str.replace("'", "-"); + str = str.replace("(", "-"); + str = str.replace(")", "-"); + str = str.replace("*", "-"); + str = str.replace("+", "-"); + str = str.replace(",", "-"); + str = str.replace(".", "-"); + str = str.replace("/", "-"); + str = str.replace(":", "-"); + str = str.replace(";", "-"); + str = str.replace("<", "-"); + str = str.replace("=", "-"); + str = str.replace(">", "-"); + str = str.replace("?", "-"); + str = str.replace("@", "-"); + str = str.replace("[", "-"); + str = str.replace("\\", "-"); + str = str.replace("]", "-"); + str = str.replace("^", "-"); + str = str.replace("_", "-"); + str = str.replace("`", "-"); + str = str.replace("{", "-"); + str = str.replace("|", "-"); + str = str.replace("}", "-"); + str = str.replace("~", "-"); + str = str.replace("ï¿ ", "-"); + str = str.replace("ï¿¡", "-"); + str = str.replace("¤", "-"); + str = str.replace("§", "-"); + str = str.replace("¨", "-"); + str = str.replace("¬", "-"); + str = str.replace("Ë", "-"); + str = str.replace("°", "-"); + str = str.replace("±", "-"); + str = str.replace("μ", "-"); + str = str.replace("â¢", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("ï¿¥", "-"); + str = str.replace("â¦â¦", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("ââ", "-"); + str = str.replace("ã", "-"); + str = str.replace("ã", "-"); + str = str.replace("ï½", "-"); + str = str.replace("ï½", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("â", "-"); + str = str.replace("ã", "-"); + str = str.replace("ã", "-"); + str = str.replace("ã", "-"); + str = str.replace("ï¼", "-"); + str = str.replace("ã", "-"); + str = str.replace("â", "-"); + str = str.replace("ï¼", "-"); + while(str.startsWith("-")){ + str = str.substring(1); + } + while(str.endsWith("-")){ + str = str.substring(0,str.length() - 1); + } + while(str.indexOf("--") != -1){ + str = str.replace("--","-"); + } + return str; + } } Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java Sun May 29 11:02:09 2011 @@ -55,7 +55,7 @@ public class CatalogUrlServlet extends H } /** - * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) + * @see javax.servlet.http.HttpServlet#init(javax.servlet.ServletConfig) */ @Override public void init(ServletConfig config) throws ServletException { @@ -147,7 +147,7 @@ public class CatalogUrlServlet extends H } /** - * @see javax.servlet.Servlet#destroy() + * @see javax.servlet.http.HttpServlet#destroy() */ @Override public void destroy() { Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java Sun May 29 11:02:09 2011 @@ -179,8 +179,8 @@ public class ProductConfigWorker { * First search persisted configurations and update configWrapper.configId if found. * Otherwise store ProductConfigWrapper to ProductConfigConfig entity and updates configWrapper.configId with new configId * This method persists only the selected options, price data is lost. - * @param ProductConfigWrapper - * @param delegator + * @param configWrapper the ProductConfigWrapper object + * @param delegator the delegator */ public static void storeProductConfigWrapper(ProductConfigWrapper configWrapper, Delegator delegator) { if (configWrapper == null || (!configWrapper.isCompleted())) return; Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java Sun May 29 11:02:09 2011 @@ -23,12 +23,8 @@ import java.awt.image.BufferedImage; import java.awt.image.ImagingOpException; import java.awt.image.RenderedImage; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.io.Writer; @@ -850,7 +846,6 @@ public class ImageManagementServices { public static Map<String, Object> resizeImageOfProduct(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); - Locale locale = (Locale) context.get("locale"); String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.management.path"), context); String imageServerUrl = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.management.url"), context); String productId = (String) context.get("productId"); Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageUrlServlet.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageUrlServlet.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageUrlServlet.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/imagemanagement/ImageUrlServlet.java Sun May 29 11:02:09 2011 @@ -50,7 +50,7 @@ public class ImageUrlServlet extends Htt } /** - * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) + * @see javax.servlet.http.HttpServlet#init(javax.servlet.ServletConfig) */ @Override public void init(ServletConfig config) throws ServletException { @@ -115,7 +115,7 @@ public class ImageUrlServlet extends Htt } /** - * @see javax.servlet.Servlet#destroy() + * @see javax.servlet.http.HttpServlet#destroy() */ @Override public void destroy() { Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java Sun May 29 11:02:09 2011 @@ -43,9 +43,9 @@ public class InventoryWorker { /** * Finds all outstanding Purchase orders for a productId. The orders and the items cannot be completed, cancelled, or rejected - * @param productId - * @param delegator - * @return + * @param productId the product id + * @param delegator the delegator + * @return returns all outstanding Purchase orders for a productId */ public static List<GenericValue> getOutstandingPurchaseOrders(String productId, Delegator delegator) { try { @@ -68,9 +68,9 @@ public class InventoryWorker { /** * Finds the net outstanding ordered quantity for a productId, netting quantity on outstanding purchase orders against cancelQuantity - * @param productId - * @param delegator - * @return + * @param productId the product id + * @param delegator the delegator + * @return returns the net outstanding ordered quantity for a productId */ public static BigDecimal getOutstandingPurchasedQuantity(String productId, Delegator delegator) { BigDecimal qty = BigDecimal.ZERO; Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/price/PriceServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/price/PriceServices.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/price/PriceServices.java Sun May 29 11:02:09 2011 @@ -21,10 +21,12 @@ package org.ofbiz.product.price; import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeSet; +import java.util.Map.Entry; import javolution.util.FastList; import javolution.util.FastMap; @@ -142,9 +144,10 @@ public class PriceServices { } // if currencyUomId is null get from properties file, if nothing there assume USD (USD: American Dollar) for now - String currencyUomId = (String) context.get("currencyUomId"); - if (UtilValidate.isEmpty(currencyUomId)) { - currencyUomId = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD"); + String currencyDefaultUomId = (String) context.get("currencyUomId"); + String currencyUomIdTo = (String) context.get("currencyUomIdTo"); + if (UtilValidate.isEmpty(currencyDefaultUomId)) { + currencyDefaultUomId = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD"); } // productPricePurposeId is null assume "PURCHASE", which is equivalent to what prices were before the purpose concept @@ -173,7 +176,7 @@ public class PriceServices { List<GenericValue> virtualProductPrices = null; if (virtualProductId != null) { try { - virtualProductPrices = delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate")); + virtualProductPrices = delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyDefaultUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate")); } catch (GenericEntityException e) { Debug.logError(e, "An error occurred while getting the product prices", module); } @@ -209,7 +212,7 @@ public class PriceServices { } else { productPriceEcList.add(EntityCondition.makeCondition("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId)); } - productPriceEcList.add(EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, currencyUomId)); + productPriceEcList.add(EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, currencyDefaultUomId)); productPriceEcList.add(EntityCondition.makeCondition("productStoreGroupId", EntityOperator.EQUALS, productStoreGroupId)); if (UtilValidate.isNotEmpty(termUomId)) { productPriceEcList.add(EntityCondition.makeCondition("termUomId", EntityOperator.EQUALS, termUomId)); @@ -229,13 +232,13 @@ public class PriceServices { List<GenericValue> listPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); GenericValue listPriceValue = EntityUtil.getFirst(listPrices); if (listPrices != null && listPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); } List<GenericValue> defaultPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); GenericValue defaultPriceValue = EntityUtil.getFirst(defaultPrices); if (defaultPrices != null && defaultPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); } // If there is an agreement between the company and the client, and there is @@ -243,7 +246,7 @@ public class PriceServices { // ProductPrice entity. if (UtilValidate.isNotEmpty(agreementId)) { try { - List<GenericValue> agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyUomId)); + List<GenericValue> agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyDefaultUomId)); GenericValue agreementPriceValue = EntityUtil.getFirst(agreementPrices); if (agreementPriceValue != null && agreementPriceValue.get("price") != null) { defaultPriceValue = agreementPriceValue; @@ -258,43 +261,43 @@ public class PriceServices { List<GenericValue> competitivePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); GenericValue competitivePriceValue = EntityUtil.getFirst(competitivePrices); if (competitivePrices != null && competitivePrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module); } List<GenericValue> averageCosts = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); GenericValue averageCostValue = EntityUtil.getFirst(averageCosts); if (averageCosts != null && averageCosts.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); } List<GenericValue> promoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); GenericValue promoPriceValue = EntityUtil.getFirst(promoPrices); if (promoPrices != null && promoPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); } List<GenericValue> minimumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); GenericValue minimumPriceValue = EntityUtil.getFirst(minimumPrices); if (minimumPrices != null && minimumPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); } List<GenericValue> maximumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); GenericValue maximumPriceValue = EntityUtil.getFirst(maximumPrices); if (maximumPrices != null && maximumPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); } List<GenericValue> wholesalePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); GenericValue wholesalePriceValue = EntityUtil.getFirst(wholesalePrices); if (wholesalePrices != null && wholesalePrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); } List<GenericValue> specialPromoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); GenericValue specialPromoPriceValue = EntityUtil.getFirst(specialPromoPrices); if (specialPromoPrices != null && specialPromoPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module); } // if any of these prices is missing and this product is a variant, default to the corresponding price on the virtual product @@ -303,56 +306,56 @@ public class PriceServices { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); listPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); } } if (defaultPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); defaultPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); } } if (averageCostValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); averageCostValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); } } if (promoPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); promoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); } } if (minimumPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); minimumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); } } if (maximumPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); maximumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); } } if (wholesalePriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); } } if (specialPromoPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module); } } } @@ -398,63 +401,63 @@ public class PriceServices { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); listPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module); } } if (defaultPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); defaultPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module); } } if (competitivePriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); competitivePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module); } } if (averageCostValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); averageCostValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module); } } if (promoPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); promoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module); } } if (minimumPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); minimumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module); } } if (maximumPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); maximumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module); } } if (wholesalePriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); } } if (specialPromoPriceValue == null) { List<GenericValue> virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { - if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); + if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyDefaultUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module); } } } @@ -493,7 +496,7 @@ public class PriceServices { if (UtilValidate.isNotEmpty(customMethod) && UtilValidate.isNotEmpty(customMethod.getString("customMethodName"))) { Map<String, Object> inMap = UtilMisc.toMap("userLogin", context.get("userLogin"), "product", product); inMap.put("initialPrice", defaultPriceValue.getBigDecimal("price")); - inMap.put("currencyUomId", currencyUomId); + inMap.put("currencyUomId", currencyDefaultUomId); inMap.put("quantity", quantity); inMap.put("amount", amount); if (UtilValidate.isNotEmpty(surveyResponseId)) { @@ -553,11 +556,11 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); + checkIncludeVat, currencyDefaultUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } else { try { - List<GenericValue> allProductPriceRules = makeProducePriceRuleList(delegator, optimizeForLargeRuleSet, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, currencyUomId); + List<GenericValue> allProductPriceRules = makeProducePriceRuleList(delegator, optimizeForLargeRuleSet, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, currencyDefaultUomId); allProductPriceRules = EntityUtil.filterByDate(allProductPriceRules, true); List<GenericValue> quantityProductPriceRules = null; @@ -576,7 +579,7 @@ public class PriceServices { if ("PRIP_QUANTITY".equals(productPriceCond.getString("inputParamEnumId"))) { foundQuantityInputParam = true; } else { - if (!checkPriceCondition(productPriceCond, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, listPrice, currencyUomId, delegator, nowTimestamp)) { + if (!checkPriceCondition(productPriceCond, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, listPrice, currencyDefaultUomId, delegator, nowTimestamp)) { allExceptQuantTrue = false; } } @@ -603,9 +606,9 @@ public class PriceServices { Map<String, Object> quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp, locale); + webSiteId, partyId, null, currencyDefaultUomId, delegator, nowTimestamp, locale); Map<String, Object> quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); + checkIncludeVat, currencyDefaultUomId, productId, quantity, partyId, dispatcher, locale); if (quantErrorResult != null) return quantErrorResult; // also add the quantityProductPriceRule to the Map so it can be used for quantity break information @@ -619,7 +622,7 @@ public class PriceServices { Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, BigDecimal.ONE, currencyUomId, delegator, nowTimestamp, locale); + webSiteId, partyId, BigDecimal.ONE, currencyDefaultUomId, delegator, nowTimestamp, locale); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to @@ -631,13 +634,13 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); + checkIncludeVat, currencyDefaultUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } else { Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, quantity, currencyUomId, delegator, nowTimestamp, locale); + webSiteId, partyId, quantity, currencyDefaultUomId, delegator, nowTimestamp, locale); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to @@ -649,7 +652,7 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); + checkIncludeVat, currencyDefaultUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } } catch (GenericEntityException e) { @@ -659,6 +662,55 @@ public class PriceServices { } } + // Convert the value to the price currency, if required + if("true".equals(UtilProperties.getPropertyValue("ecommerce.properties", "convertProductPriceCurrency"))){ + if (UtilValidate.isNotEmpty(currencyDefaultUomId) && UtilValidate.isNotEmpty(currencyUomIdTo) && !currencyDefaultUomId.equals(currencyUomIdTo)) { + if(UtilValidate.isNotEmpty(result)){ + Map<String, Object> convertPriceMap = FastMap.newInstance(); + Iterator<Entry<String, Object>> it= result.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry<String, Object> entry = it.next(); + BigDecimal tempPrice = BigDecimal.ZERO; + if(entry.getKey() == "basePrice") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "price") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "defaultPrice") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "competitivePrice") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "averageCost") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "promoPrice") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "specialPromoPrice") + tempPrice = (BigDecimal) entry.getValue(); + else if (entry.getKey() == "listPrice") + tempPrice = (BigDecimal) entry.getValue(); + + if(tempPrice != null && tempPrice != BigDecimal.ZERO){ + Map<String, Object> priceResults = FastMap.newInstance(); + try { + priceResults = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", currencyDefaultUomId, "uomIdTo", currencyUomIdTo, "originalValue", tempPrice , "defaultDecimalScale" , Long.valueOf(2) , "defaultRoundingMode" , "HalfUp")); + if (ServiceUtil.isError(priceResults) || (priceResults.get("convertedValue") == null)) { + Debug.logWarning("Unable to convert " + entry.getKey() + " for product " + productId , module); + } + } catch (GenericServiceException e) { + Debug.logError(e, module); + } + convertPriceMap.put(entry.getKey(), priceResults.get("convertedValue")); + }else{ + convertPriceMap.put(entry.getKey(), entry.getValue()); + } + } + if(UtilValidate.isNotEmpty(convertPriceMap)){ + convertPriceMap.put("currencyUsed", currencyUomIdTo); + result = convertPriceMap; + } + } + } + } + // utilTimer.timerString("Finished price calc [productId=" + productId + "]", module); return result; } Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Sun May 29 11:02:09 2011 @@ -152,19 +152,22 @@ public class ProductSearchSession { } /** - * @return Returns the viewIndex. + * Get the view size + * @return returns the viewIndex. */ public Integer getViewIndex() { return viewIndex; } /** - * @param viewIndex The viewIndex to set. + * Set the view index + * @param viewIndex the viewIndex to set. */ public void setViewIndex(Integer viewIndex) { this.viewIndex = viewIndex; } /** - * @param viewIndex The viewIndex to set. + * Set the view index + * @param viewIndexStr the viewIndex to set. */ public void setViewIndex(String viewIndexStr) { if (UtilValidate.isEmpty(viewIndexStr)) { @@ -181,14 +184,16 @@ public class ProductSearchSession { } /** - * @return Returns the viewSize. + * Get the view size + * @return returns the view size. */ public Integer getViewSize() { return viewSize; } /** - * @param viewSize The viewSize to set. + * Set the view size + * @param viewSize the view size to set. */ public void setViewSize(Integer viewSize) { setPreviousViewSize(getViewSize()); @@ -196,7 +201,8 @@ public class ProductSearchSession { } /** - * @param viewSize The viewSize to set. + * Set the view size + * @param viewSizeStr the view size to set. */ public void setViewSize(String viewSizeStr) { if (UtilValidate.isEmpty(viewSizeStr)) { @@ -213,14 +219,16 @@ public class ProductSearchSession { } /** - * @return Returns the paging. + * Get the paging + * @return Returns the paging */ public String getPaging() { return paging; } /** - * @param paging The paging to set. + * Set the paging + * @param paging the paging to set */ public void setPaging(String paging) { if (paging == null) { @@ -230,13 +238,15 @@ public class ProductSearchSession { } /** - * @return Returns the previousViewSize. + * Get the previous view size + * @return returns the previous view size */ public Integer getPreviousViewSize() { return previousViewSize; } /** - * @param previousViewSize The previousViewSize to set. + * Set the previous view size + * @param previousViewSize the previousViewSize to set. */ public void setPreviousViewSize(Integer previousViewSize) { if (previousViewSize == null) { Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductServices.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductServices.java Sun May 29 11:02:09 2011 @@ -28,6 +28,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; import java.sql.Timestamp; import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -870,7 +871,7 @@ public class ProductServices { Set<String> featureProductIds = FastSet.newInstance(); featureProductIds.add(productId); featureProductIds.addAll(variantProductsById.keySet()); - Set<String> productFeatureIds = FastSet.newInstance(); + Set<String> productFeatureIds = new HashSet<String>(); productFeatureIds.add(productFeatureIdOne); productFeatureIds.add(productFeatureIdTwo); productFeatureIds.add(productFeatureIdThree); @@ -1224,9 +1225,8 @@ public class ProductServices { /** * Finds productId(s) corresponding to a product reference, productId or a GoodIdentification idValue - * @param dctx - * @param context - * @param context.productId use to search with productId or goodIdentification.idValue + * @param ctx the dispatch context + * @param context productId use to search with productId or goodIdentification.idValue * @return a GenericValue with a productId and a List of complementary productId found */ public static Map<String, Object> findProductById(DispatchContext ctx, Map<String, Object> context) { Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/product/ProductWorker.java Sun May 29 11:02:09 2011 @@ -842,12 +842,12 @@ public class ProductWorker { * By default return the product find by productId * but you can pass searchProductFirst at false if you want search in goodIdentification before * or pass searchAllId at true to find all product with this id (product.productId and goodIdentification.idValue) - * @param delegator - * @param idToFind - * @param goodIdentificationTypeId - * @param searchProductFirst - * @param searchAllId - * @return + * @param delegator the delegator + * @param idToFind the product id to find + * @param goodIdentificationTypeId the good identification type id to use + * @param searchProductFirst search first by product id + * @param searchAllId search all product ids + * @return return the list of products founds * @throws GenericEntityException */ public static List<GenericValue> findProductsById(Delegator delegator, @@ -1180,6 +1180,10 @@ nextProd: * @throws GenericEntityException to catch */ public static Boolean isDecimalQuantityOrderAllowed(Delegator delegator, String poductId, String productStoreId) throws GenericEntityException{ + //sometime productStoreId may be null (ie PO), then return default value which is TRUE + if(UtilValidate.isEmpty(productStoreId)){ + return Boolean.TRUE; + } String allowDecimalStore = delegator.findOne("ProductStore", Boolean.TRUE, UtilMisc.toMap("productStoreId", productStoreId)).getString("orderDecimalQuantity"); String allowDecimalProduct = delegator.findOne("Product", Boolean.TRUE, UtilMisc.toMap("productId", poductId)).getString("orderDecimalQuantity"); Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java Sun May 29 11:02:09 2011 @@ -57,9 +57,9 @@ public class ImportProductServices { * Note : Create the spreadsheet directory in the ofbiz home folder and keep * your xls files in this folder only. * - * @param dctx - * @param context - * @return + * @param dctx the dispatch context + * @param context the context + * @return the result of the service execution */ public static Map<String, Object> productImportFromSpreadsheet(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); Modified: ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java?rev=1128865&r1=1128864&r2=1128865&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java (original) +++ ofbiz/branches/jackrabbit20100709/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java Sun May 29 11:02:09 2011 @@ -87,9 +87,9 @@ public class PackingServices { * Packs the same items n times in consecutive packages, starting from the package number retrieved from pkgInfo.</li> * </ul> * </p> - * @param dctx - * @param context - * @return + * @param dctx the dispatch context + * @param context the context + * @return returns the result of the service execution */ public static Map<String, Object> packBulk(DispatchContext dctx, Map<String, ? extends Object> context) { PackingSession session = (PackingSession) context.get("packingSession"); |
Free forum by Nabble | Edit this page |