Author: lektran
Date: Wed Sep 16 02:50:26 2009
New Revision: 815592
URL:
http://svn.apache.org/viewvc?rev=815592&view=revLog:
Add a new ProductWorker method that determines the standard features of a variant that would qualify it for selection from its virtual product, a reverse lookup of sorts
Modified:
ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=815592&r1=815591&r2=815592&view=diff==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java Wed Sep 16 02:50:26 2009
@@ -547,6 +547,38 @@
}
return featureTypeFeatures;
}
+
+ /**
+ * For a given variant product, returns the list of features that would qualify it for
+ * selection from the virtual product
+ * @param variantProduct - the variant from which to derive the selection features
+ * @return a List of ProductFeature GenericValues
+ */
+ public static List<GenericValue> getVariantSelectionFeatures(GenericValue variantProduct) {
+ if (!"Y".equals(variantProduct.getString("isVariant"))) {
+ return null;
+ }
+ GenericValue virtualProduct = ProductWorker.getParentProduct(variantProduct.getString("productId"), variantProduct.getDelegator());
+ if (virtualProduct == null || !"Y".equals(virtualProduct.getString("productId"))) {
+ return null;
+ }
+ // The selectable features from the virtual product
+ List<GenericValue> selectableFeatures = ProductWorker.getProductFeaturesByApplTypeId(virtualProduct, "SELECTABLE_FEATURE");
+ // A list of distinct ProductFeatureTypes derived from the selectable features
+ List<String> selectableTypes = EntityUtil.getFieldListFromEntityList(selectableFeatures, "productFeatureTypeId", true);
+ // The standard features from the variant product
+ List<GenericValue> standardFeatures = ProductWorker.getProductFeaturesByApplTypeId(variantProduct, "STANDARD_FEATURE");
+ List<GenericValue> result = FastList.newInstance();
+ for (GenericValue standardFeature : standardFeatures) {
+ // For each standard variant feature check it is also a virtual selectable feature and
+ // if a feature of the same type hasn't already been added to the list
+ if (selectableTypes.contains(standardFeature.getString("productFeatureTypeId")) && selectableFeatures.contains(standardFeature)) {
+ result.add(standardFeature);
+ selectableTypes.remove(standardFeature.getString("productFeatureTypeId"));
+ }
+ }
+ return result;
+ }
public static Map<String, List<GenericValue>> getOptionalProductFeatures(GenericDelegator delegator, String productId) {
Map<String, List<GenericValue>> featureMap = new LinkedHashMap<String, List<GenericValue>>();