svn commit: r1078764 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java

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

svn commit: r1078764 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java

sascharodekamp
Author: sascharodekamp
Date: Mon Mar  7 12:53:25 2011
New Revision: 1078764

URL: http://svn.apache.org/viewvc?rev=1078764&view=rev
Log:
Improvement - ProductContentWrapper didn't return ProductContent for virtual products (https://issues.apache.org/jira/browse/OFBIZ-4204).

Orig.Msg.:
Calling ProductContentWrapper.getProductContentAsText() for variant products:
When the method checks if "ProductContent" exists, it did not differ bedween variant and other products.
So if the ProductContent is empty for variant products, it did not check if the parentProduct has ProductContent of this type that could be returned.

This Patch improves the ProductContentWrapper to check variant products parent for ProductContent if thier content is empty.


Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java?rev=1078764&r1=1078763&r2=1078764&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java Mon Mar  7 12:53:25 2011
@@ -153,11 +153,15 @@ public class ProductContentWrapper imple
 
         String candidateFieldName = ModelUtil.dbNameToVarName(productContentTypeId);
         ModelEntity productModel = delegator.getModelEntity("Product");
+        if (product == null) {
+            product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
+        }
+        if (UtilValidate.isEmpty(product)) {
+            Debug.logWarning("No Product entity found for productId: " + productId, module);
+            return;
+        }
+        
         if (productModel.isField(candidateFieldName)) {
-            if (product == null) {
-                product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
-            }
-            if (product != null) {
                 String candidateValue = product.getString(candidateFieldName);
                 if (UtilValidate.isNotEmpty(candidateValue)) {
                     outWriter.write(candidateValue);
@@ -173,11 +177,17 @@ public class ProductContentWrapper imple
                         }
                     }
                 }
-            }
         }
 
         List<GenericValue> productContentList = delegator.findByAndCache("ProductContent", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"));
         productContentList = EntityUtil.filterByDate(productContentList);
+        if (UtilValidate.isEmpty(productContentList) && ("Y".equals(product.getString("isVariant")))) {
+            GenericValue parent = ProductWorker.getParentProduct(productId, delegator);
+            if (UtilValidate.isNotEmpty(parent)) {
+                productContentList = delegator.findByAndCache("ProductContent", UtilMisc.toMap("productId", parent.get("productId"), "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate"));
+                productContentList = EntityUtil.filterByDate(productContentList);
+            }
+        }
         GenericValue productContent = EntityUtil.getFirst(productContentList);
         if (productContent != null) {
             // when rendering the product content, always include the Product and ProductContent records that this comes from