You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ha...@apache.org on 2011/08/10 07:56:50 UTC

svn commit: r1156035 - in /ofbiz/trunk: applications/product/src/org/ofbiz/product/category/ specialpurpose/ecommerce/widget/

Author: hansbak
Date: Wed Aug 10 05:56:50 2011
New Revision: 1156035

URL: http://svn.apache.org/viewvc?rev=1156035&view=rev
Log:
the product url on the order confirmation email didn't display because ofbizCatalogAltUrl don't return the URL when request not found: fixed

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java
    ofbiz/trunk/specialpurpose/ecommerce/widget/EmailOrderScreens.xml

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java?rev=1156035&r1=1156034&r2=1156035&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java Wed Aug 10 05:56:50 2011
@@ -338,97 +338,112 @@ 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);
-            StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
-            
-            if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
-                StringBuilder urlBuilder = new StringBuilder();
-                urlBuilder.append(request.getSession().getServletContext().getContextPath());
-                if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
-                    urlBuilder.append("/");
-                }
-                // append alternative URL
-                url = UrlServletHelper.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("&")) {
-                        urlBuilder.append("?");
-                    }
-                    urlBuilder.append("viewIndex=" + viewIndex + "&");
-                }
-                // append view size
-                if (UtilValidate.isNotEmpty(viewSize)) {
-                    if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
-                        urlBuilder.append("?");
-                    }
-                    urlBuilder.append("viewSize=" + viewSize + "&");
+            return makeCategoryUrl(delegator, wrapper, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e, "Cannot create category's URL for: " + productCategoryId, module);
+            return redirectUrl;
+        }
+    }
+
+    public static String makeCategoryUrl(Delegator delegator, CategoryContentWrapper wrapper, String contextPath, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) {
+    	String url = "";
+    	StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
+        
+        if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
+            StringBuilder urlBuilder = new StringBuilder();
+            urlBuilder.append(contextPath);
+            if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+                urlBuilder.append("/");
+            }
+            // append alternative URL
+            url = UrlServletHelper.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("&")) {
+                    urlBuilder.append("?");
                 }
-                // append view sort
-                if (UtilValidate.isNotEmpty(viewSort)) {
-                    if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
-                        urlBuilder.append("?");
-                    }
-                    urlBuilder.append("viewSort=" + viewSort + "&");
+                urlBuilder.append("viewIndex=" + viewIndex + "&");
+            }
+            // append view size
+            if (UtilValidate.isNotEmpty(viewSize)) {
+                if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+                    urlBuilder.append("?");
                 }
-                // append search string
-                if (UtilValidate.isNotEmpty(searchString)) {
-                    if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
-                        urlBuilder.append("?");
-                    }
-                    urlBuilder.append("searchString=" + searchString + "&");
+                urlBuilder.append("viewSize=" + viewSize + "&");
+            }
+            // append view sort
+            if (UtilValidate.isNotEmpty(viewSort)) {
+                if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+                    urlBuilder.append("?");
                 }
-                if (urlBuilder.toString().endsWith("&")) {
-                    return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1);
+                urlBuilder.append("viewSort=" + viewSort + "&");
+            }
+            // append search string
+            if (UtilValidate.isNotEmpty(searchString)) {
+                if (!urlBuilder.toString().endsWith("?") && !urlBuilder.toString().endsWith("&")) {
+                    urlBuilder.append("?");
                 }
-                
-                return  urlBuilder.toString();
-            } else {
-                return CatalogUrlServlet.makeCatalogUrl(request, productId, productCategoryId, previousCategoryId);
+                urlBuilder.append("searchString=" + searchString + "&");
             }
-        } catch (GenericEntityException e) {
-            Debug.logWarning(e, "Cannot create category's URL for: " + productCategoryId, module);
-            return redirectUrl;
+            if (urlBuilder.toString().endsWith("&")) {
+                return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1);
+            }
+            
+            url = urlBuilder.toString();
+        } else {
+        	List<String> crumb = FastList.newInstance();
+        	String currentCategoryId = null;
+        	url = CatalogUrlServlet.makeCatalogUrl(contextPath, crumb, productId, currentCategoryId, previousCategoryId);
         }
+    	return url;
     }
     
     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);
-            StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
-            if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
-                StringBuilder urlBuilder = new StringBuilder();
-                urlBuilder.append(request.getSession().getServletContext().getContextPath());
-                if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
-                    urlBuilder.append("/");
-                }
-                // append alternative URL
-                url = UrlServletHelper.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);
-            }
+	        GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
+	        ProductContentWrapper wrapper = new ProductContentWrapper(product, request);
+	        url = makeProductUrl(delegator, wrapper, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId);
         } catch (GenericEntityException e) {
             Debug.logWarning(e, "Cannot create product's URL for: " + productId, module);
             return redirectUrl;
         }
+        return url;
+    }
+
+    public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper, String contextPath, String previousCategoryId, String productCategoryId, String productId) {
+        String url = "";
+        StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
+        if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
+            StringBuilder urlBuilder = new StringBuilder();
+            urlBuilder.append(contextPath);
+            if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+                urlBuilder.append("/");
+            }
+            // append alternative URL
+            url = UrlServletHelper.invalidCharacter(alternativeUrl.toString());
+            urlBuilder.append(url);
+            if (UtilValidate.isNotEmpty(productId)) {
+                urlBuilder.append("-");
+                urlBuilder.append(productId);
+                urlBuilder.append("-p");
+            }
+            url = urlBuilder.toString();
+        } else {
+        	List<String> crumb = FastList.newInstance();
+        	String currentCategoryId = null;
+        	url = CatalogUrlServlet.makeCatalogUrl(contextPath, crumb, productId, currentCategoryId, previousCategoryId);
+        }
+        return url;
     }
-    
 }

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java?rev=1156035&r1=1156034&r2=1156035&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlServlet.java Wed Aug 10 05:56:50 2011
@@ -179,4 +179,29 @@ public class CatalogUrlServlet extends H
 
         return urlBuilder.toString();
     }
+
+    public static String makeCatalogUrl(String contextPath, List<String> crumb, String productId, String currentCategoryId, String previousCategoryId) {
+        StringBuilder urlBuilder = new StringBuilder();
+        urlBuilder.append(contextPath);
+        if (urlBuilder.charAt(urlBuilder.length() - 1) != '/') {
+            urlBuilder.append("/");
+        }
+        urlBuilder.append(CATALOG_URL_MOUNT_POINT);
+
+        if (UtilValidate.isNotEmpty(currentCategoryId)) {
+        	crumb = CategoryWorker.adjustTrail(crumb, currentCategoryId, previousCategoryId);
+            for (String trailCategoryId: crumb) {
+                if ("TOP".equals(trailCategoryId)) continue;
+                urlBuilder.append("/");
+                urlBuilder.append(trailCategoryId);
+            }
+        }
+
+        if (UtilValidate.isNotEmpty(productId)) {
+            urlBuilder.append("/p_");
+            urlBuilder.append(productId);
+        }
+
+        return urlBuilder.toString();
+    }
 }

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java?rev=1156035&r1=1156034&r2=1156035&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java Wed Aug 10 05:56:50 2011
@@ -20,11 +20,20 @@ package org.ofbiz.product.category;
 
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
+
+import org.ofbiz.base.util.template.FreeMarkerWorker;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.product.product.ProductContentWrapper;
+import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.webapp.control.RequestHandler;
 
 import freemarker.core.Environment;
@@ -87,35 +96,55 @@ public class OfbizCatalogAltUrlTransform
             
             public void close() throws IOException {
                 try {
-                Environment env = Environment.getCurrentEnvironment();
-                BeanModel req = (BeanModel) env.getVariable("request");
-                if (req != null) {
+                    Environment env = Environment.getCurrentEnvironment();
+                    BeanModel req = (BeanModel) env.getVariable("request");
                     String previousCategoryId = getStringArg(args, "previousCategoryId");
                     String productCategoryId = getStringArg(args, "productCategoryId");
                     String productId = getStringArg(args, "productId");
-                    
-                    HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                     String url = "";
-                    StringBuilder newURL = new StringBuilder();
-                    if (UtilValidate.isNotEmpty(productId)) {
-                        url = CatalogUrlFilter.makeProductUrl(request, previousCategoryId, productCategoryId, productId);
+                    
+                    Object prefix = env.getVariable("urlPrefix");
+                    String viewSize = getStringArg(args, "viewSize");
+                    String viewIndex = getStringArg(args, "viewIndex");
+                    String viewSort = getStringArg(args, "viewSort");
+                    String searchString = getStringArg(args, "searchString");
+                    if (req != null) {
+                        
+                        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
+                        StringBuilder newURL = new StringBuilder();
+                        if (UtilValidate.isNotEmpty(productId)) {
+                            url = CatalogUrlFilter.makeProductUrl(request, previousCategoryId, productCategoryId, productId);
+                        } else {
+                            url = CatalogUrlFilter.makeCategoryUrl(request, previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+                        }
+                        // make the link
+                        if (fullPath){
+                            String serverRootUrl = RequestHandler.getDefaultServerRootUrl(request, secure);
+                            newURL.append(serverRootUrl);
+                        }
+                        newURL.append(url);
+                        out.write(newURL.toString());
+                    } else if (prefix != null) {
+                        Delegator delegator = FreeMarkerWorker.getWrappedObject("delegator", env);
+                        LocalDispatcher dispatcher = FreeMarkerWorker.getWrappedObject("dispatcher", env);
+                        Locale locale = (Locale) args.get("locale");
+                        if (UtilValidate.isNotEmpty(productId)) {
+                            GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
+                            ProductContentWrapper wrapper = new ProductContentWrapper(dispatcher, product, locale, "text/html");
+                            url = CatalogUrlFilter.makeProductUrl(delegator, wrapper, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId);
+                        } else {
+                            GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), false);
+                            CategoryContentWrapper wrapper = new CategoryContentWrapper(dispatcher, productCategory, locale, "text/html");
+                            url = CatalogUrlFilter.makeCategoryUrl(delegator, wrapper, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+                        }
+                        out.write(url.toString());
                     } else {
-                        String viewSize = getStringArg(args, "viewSize");
-                        String viewIndex = getStringArg(args, "viewIndex");
-                        String viewSort = getStringArg(args, "viewSort");
-                        String searchString = getStringArg(args, "searchString");
-                        url = CatalogUrlFilter.makeCategoryUrl(request, previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+                        out.write(buf.toString());
                     }
-                    // make the link
-                    if (fullPath){
-                        String serverRootUrl = RequestHandler.getDefaultServerRootUrl(request, secure);
-                        newURL.append(serverRootUrl);
-                    }
-                    newURL.append(url);
-                    out.write(newURL.toString());
-                }
                 } catch (TemplateModelException e) {
                     throw new IOException(e.getMessage());
+                } catch (GenericEntityException e) {
+                    throw new IOException(e.getMessage());
                 }
             }
         };

Modified: ofbiz/trunk/specialpurpose/ecommerce/widget/EmailOrderScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/widget/EmailOrderScreens.xml?rev=1156035&r1=1156034&r2=1156035&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/widget/EmailOrderScreens.xml (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/widget/EmailOrderScreens.xml Wed Aug 10 05:56:50 2011
@@ -30,7 +30,7 @@ under the License.
                 <property-map resource="ProductUiLabels" map-name="uiLabelMap" global="true"/>
                 <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                 <set field="title" value="${uiLabelMap.PageTitleOrderConfirmationNotice}"/>
-                <set field="baseEcommerceSecureUrl" value="${baseSecureUrl}/ecommerce/control/"/>
+                <set field="baseEcommerceSecureUrl" value="${baseSecureUrl}/ecommerce"/>
                 <set field="title" value="Order"/>
                 <script location="component://order/webapp/ordermgr/WEB-INF/actions/order/OrderView.groovy"/>
             </actions>
@@ -84,7 +84,7 @@ under the License.
                 <property-map resource="OrderUiLabels" map-name="uiLabelMap" global="true"/>
                 <property-map resource="PartyUiLabels" map-name="uiLabelMap" global="true"/>
                 <set field="title" value="${uiLabelMap.PageTitleOrderConfirmationNotice}"/>
-                <set field="baseEcommerceSecureUrl" value="${baseSecureUrl}/ecommerce/control/"/>
+                <set field="baseEcommerceSecureUrl" value="${baseSecureUrl}/ecommerce"/>
                 <set field="allowAnonymousView" value="Y"/>  <!-- this field will instruction OrderStatus.groovy to allow an anonymous order to be viewed by anybody, so the email confirmation screen will work -->
                 <script location="component://ecommerce/webapp/ecommerce/WEB-INF/actions/order/OrderStatus.groovy"/>
             </actions>