Author: deepak Date: Sat May 16 10:35:02 2015 New Revision: 1679720 URL: http://svn.apache.org/r1679720 Log: Applied patch from jira issue OFBIZ-6262 -CategoryContentWrapper ignores session locale
Thanks Josip Almasi for issue reporting and providing the patch. Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java?rev=1679720&r1=1679719&r2=1679720&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java Sat May 16 10:35:02 2015 @@ -33,6 +33,7 @@ import org.ofbiz.base.util.GeneralExcept import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.content.content.ContentWorker; import org.ofbiz.content.content.ContentWrapper; @@ -141,7 +142,23 @@ public class CategoryContentWrapper impl List<GenericValue> categoryContentList = EntityQuery.use(delegator).from("ProductCategoryContent").where("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId).orderBy("-fromDate").cache(true).queryList(); categoryContentList = EntityUtil.filterByDate(categoryContentList); - GenericValue categoryContent = EntityUtil.getFirst(categoryContentList); + + GenericValue categoryContent = null; + String sessionLocale = locale.toString(); + String fallbackLocale = UtilProperties.getFallbackLocale().toString(); + if ( sessionLocale == null ) sessionLocale = fallbackLocale; + // look up all content found for locale + for( GenericValue currentContent: categoryContentList ) { + GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", currentContent.getString("contentId")).cache().queryOne(); + if ( sessionLocale.equals(content.getString("localeString")) ) { + // valid locale found + categoryContent = currentContent; + break; + } else if ( fallbackLocale.equals(content.getString("localeString")) ) { + // fall back to default locale + categoryContent = currentContent; + } + } if (categoryContent != null) { // when rendering the category content, always include the Product Category and ProductCategoryContent records that this comes from Map<String, Object> inContext = new HashMap<String, Object>();