Fixed: Wrong locale/fallbackLocale logic in CategoryContentWrapper leads
to unavailable alternate locale content.
Thanks Martin Becker for reporting and providing the patch.
@@ -34,7 +34,6 @@ import org.apache.ofbiz.base.util.GeneralRuntimeException;
import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilCodec;
import org.apache.ofbiz.base.util.UtilHttp;
-import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.base.util.cache.UtilCache;
import org.apache.ofbiz.content.content.ContentWorker;
@@ -143,25 +142,8 @@ public class CategoryContentWrapper implements ContentWrapper {
throw new GeneralRuntimeException("Unable to find a delegator to use!");
}
- List<GenericValue> categoryContentList = EntityQuery.use(delegator).from("ProductCategoryContent").where("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId).orderBy("-fromDate").cache(cache).queryList();
- categoryContentList = EntityUtil.filterByDate(categoryContentList);
-
- GenericValue categoryContent = null;
- String sessionLocale = (locale != null ? locale.toString() : null);
- 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(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;
- }
- }
+ List<GenericValue> categoryContentList = EntityQuery.use(delegator).from("ProductCategoryContent").where("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId).orderBy("-fromDate").cache(cache).filterByDate().queryList();
+ GenericValue categoryContent = EntityUtil.getFirst(categoryContentList);
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>();
