svn commit: r1156536 - in /ofbiz/trunk/applications/product/src/org/ofbiz/product/category: CatalogUrlFilter.java OfbizCatalogAltUrlTransform.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1156536 - in /ofbiz/trunk/applications/product/src/org/ofbiz/product/category: CatalogUrlFilter.java OfbizCatalogAltUrlTransform.java

hansbak-2
Author: hansbak
Date: Thu Aug 11 08:34:14 2011
New Revision: 1156536

URL: http://svn.apache.org/viewvc?rev=1156536&view=rev
Log:
seo friendly url had wrong category url because the tail category was missing.

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/OfbizCatalogAltUrlTransform.java

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=1156536&r1=1156535&r2=1156536&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 Thu Aug 11 08:34:14 2011
@@ -341,16 +341,17 @@ public class CatalogUrlFilter extends Co
         try {
             GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), true);
             CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request);
-            return makeCategoryUrl(delegator, wrapper, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
+            List<String> trail = CategoryWorker.getTrail(request);
+            return makeCategoryUrl(delegator, wrapper, trail, 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");
+    public static String makeCategoryUrl(Delegator delegator, CategoryContentWrapper wrapper, List<String> trail, 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();
@@ -400,20 +401,23 @@ public class CatalogUrlFilter extends Co
             
             url = urlBuilder.toString();
         } else {
-         List<String> crumb = FastList.newInstance();
-         String currentCategoryId = null;
-         url = CatalogUrlServlet.makeCatalogUrl(contextPath, crumb, productId, currentCategoryId, previousCategoryId);
+            if(UtilValidate.isEmpty(trail)){
+                trail = FastList.newInstance();
+            }
+            url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId);
         }
-     return url;
+        
+        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);
-        url = makeProductUrl(delegator, wrapper, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId);
+            GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
+            ProductContentWrapper wrapper = new ProductContentWrapper(product, request);
+            List<String> trail = CategoryWorker.getTrail(request);
+            url = makeProductUrl(delegator, wrapper, trail, request.getSession().getServletContext().getContextPath(), previousCategoryId, productCategoryId, productId);
         } catch (GenericEntityException e) {
             Debug.logWarning(e, "Cannot create product's URL for: " + productId, module);
             return redirectUrl;
@@ -421,7 +425,7 @@ public class CatalogUrlFilter extends Co
         return url;
     }
 
-    public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper, String contextPath, String previousCategoryId, String productCategoryId, String productId) {
+    public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper,List<String> trail, String contextPath, String previousCategoryId, String productCategoryId, String productId) {
         String url = "";
         StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL");
         if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
@@ -440,9 +444,10 @@ public class CatalogUrlFilter extends Co
             }
             url = urlBuilder.toString();
         } else {
-         List<String> crumb = FastList.newInstance();
-         String currentCategoryId = null;
-         url = CatalogUrlServlet.makeCatalogUrl(contextPath, crumb, productId, currentCategoryId, previousCategoryId);
+            if(UtilValidate.isEmpty(trail)){
+                trail = FastList.newInstance();
+            }
+            url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId);
         }
         return url;
     }

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=1156536&r1=1156535&r2=1156536&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 Thu Aug 11 08:34:14 2011
@@ -109,7 +109,6 @@ public class OfbizCatalogAltUrlTransform
                     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)) {
@@ -131,11 +130,11 @@ public class OfbizCatalogAltUrlTransform
                         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);
+                            url = CatalogUrlFilter.makeProductUrl(delegator, wrapper, null, ((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);
+                            url = CatalogUrlFilter.makeCategoryUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
                         }
                         out.write(url.toString());
                     } else {