svn commit: r645387 - in /ofbiz/trunk/applications: order/config/OrderUiLabels.xml order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java product/entitydef/entitymodel.xml product/src/org/ofbiz/product/product/ProductWorker.java

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

svn commit: r645387 - in /ofbiz/trunk/applications: order/config/OrderUiLabels.xml order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java product/entitydef/entitymodel.xml product/src/org/ofbiz/product/product/ProductWorker.java

hansbak-2
Author: hansbak
Date: Sun Apr  6 23:00:59 2008
New Revision: 645387

URL: http://svn.apache.org/viewvc?rev=645387&view=rev
Log:
next version of the alternative variant selection method

Modified:
    ofbiz/trunk/applications/order/config/OrderUiLabels.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
    ofbiz/trunk/applications/product/entitydef/entitymodel.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java

Modified: ofbiz/trunk/applications/order/config/OrderUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderUiLabels.xml?rev=645387&r1=645386&r2=645387&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/config/OrderUiLabels.xml (original)
+++ ofbiz/trunk/applications/order/config/OrderUiLabels.xml Sun Apr  6 23:00:59 2008
@@ -10623,6 +10623,9 @@
         <value xml:lang="th">ข้อมูลสินค้าไม่ผ่าน ไม่สามารถเพิ่มสินค้าลงตระกร้า</value>
         <value xml:lang="zh">没有传递产品信息,没有向购物车添加任何明细。</value>
     </property>
+    <property key="cart.addToCart.incompatibilityVariantFeature">
+        <value xml:lang="en">You cannot use selection ${productFutureDescription} </value>
+    </property>
     <property key="cart.addToCart.productConfigurationIsNotValid">
         <value xml:lang="en">Configuration Is Not Valid</value>
         <value xml:lang="es">La configuración no es válida</value>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=645387&r1=645386&r2=645387&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Sun Apr  6 23:00:59 2008
@@ -156,7 +156,12 @@
         if (paramMap.containsKey("ADD_PRODUCT_ID")) {
             productId = (String) paramMap.remove("ADD_PRODUCT_ID");
         } else if (paramMap.containsKey("add_product_id")) {
-            productId = (String) paramMap.remove("add_product_id");
+         Object object = paramMap.remove("add_product_id");
+         try{
+         productId = (String) object;
+         }catch(ClassCastException e){
+         productId = (String)((List)object).get(0);
+         }
         }
         if (paramMap.containsKey("PRODUCT_ID")) {
             parentProductId = (String) paramMap.remove("PRODUCT_ID");
@@ -232,24 +237,120 @@
             }
         }
         
+  
         //Check for virtual products
         if (ProductWorker.isVirtual(delegator, productId)) {
-        
-         if ("VV_FEATURETREE".equals(ProductWorker.getProductvirtualVariantMethod(delegator, productId))) {
-         // new variant selection: try to find variants using the selected features
-         List featureTypes = ProductWorker.getProductFeatureTypesBySeq(delegator, productId);
-        
-        
-         // to be continued.......
-        
-        
-        
-         } else {
-         request.setAttribute("product_id", productId);
-         request.setAttribute("_EVENT_MESSAGE_", UtilProperties.getMessage(resource, "cart.addToCart.chooseVariationBeforeAddingToCart", locale));
-         return "product";
-         }
-        }
+
+ if ("VV_FEATURETREE".equals(ProductWorker.getProductvirtualVariantMethod(delegator, productId))) {
+
+ // get the selected features.
+ List <String> selectedFeatures = new LinkedList<String>();
+     java.util.Enumeration paramNames = request.getParameterNames();
+     while(paramNames.hasMoreElements()) {
+     String paramName = (String)paramNames.nextElement();
+     if (paramName.startsWith("FT")) {
+     selectedFeatures.add(request.getParameterValues(paramName)[0]);
+     }
+//        Debug.log("********paramName/"+paramName+"/");
+//     String[] paramValues = request.getParameterValues(paramName);
+//     StringBuffer paraValue= new StringBuffer();
+//     for(int i=0; i<paramValues.length; i++) {
+//     paraValue.append(paramValues[i]+",");              
+//        }
+//     Debug.log(paraValue.toString());
+     }
+ try {
+
+ List<GenericValue> dependenciesVariants = delegator.findByAndCache("ProductFeatureIactn", UtilMisc.toMap("productId", productId,
+ "productFeatureIactnTypeId","FEATURE_IACTN_DEPEND"));
+ List<GenericValue> incompatibilityVariants = delegator.findByAndCache("ProductFeatureIactn", UtilMisc.toMap("productId", productId,
+ "productFeatureIactnTypeId","FEATURE_IACTN_INCOMP"));
+ // find incompatibilities or dependencies...
+ List <GenericValue> featureTypes = ProductWorker.getProductFeatureTypesBySeq(delegator, productId);
+ Iterator<GenericValue> featureIter = featureTypes.iterator();
+
+ while (featureIter.hasNext()) {
+ String paramValue = (String) paramMap.get("FT") + featureIter.next();
+ Iterator<GenericValue> incompatibilityVariantIter = incompatibilityVariants.iterator();
+ while (incompatibilityVariantIter.hasNext()) {
+ GenericValue incompatibilityVariant = incompatibilityVariantIter.next();
+ String featur = incompatibilityVariant.getString("productFeatureId");
+ if(paramValue.equals(featur)){
+ String featurTo = incompatibilityVariant.getString("productFeatureIdTo");
+ Iterator<GenericValue> featureToIter = featureTypes.iterator();
+ while (featureToIter.hasNext()) {
+ String paramValueTo = (String) paramMap.get("FT" + featureToIter.next());
+ if(featurTo.equals(paramValueTo)){
+ GenericValue featureFrom = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featur));
+ GenericValue featureTo = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featurTo));
+
+ String message = UtilProperties.getMessage(resource, "cart.addToCart.incompatibilityVariantFeature", locale) + ":/" + featureFrom.getString("description") + "/ => /" + featureTo.getString("description") +"/";
+ Debug.log(">>>>>>>" + message);
+ request.setAttribute("_ERROR_MESSAGE_", message);
+ return "incompatibilityVariantFeature";
+ }
+ }
+
+ }
+ }
+
+ }
+
+ request.setAttribute("_EVENT_MESSAGE_","all feature Variant accept");
+ Iterator<String> fIter = selectedFeatures.iterator();
+ Long lowestCount = null;
+ String lowestFeatureId = null;
+ while (fIter.hasNext()) {
+ String productFeatureId = fIter.next();
+ long r = delegator.findCountByAnd("ProductFeatureAppl", UtilMisc.toMap("productFeatureId", productFeatureId,"productFeatureApplTypeId","STANDARD_FEATURE"));
+ if (lowestCount == null || r < lowestCount) {
+ lowestCount = r;
+ lowestFeatureId = productFeatureId;
+ }
+ }
+ // find variant
+ List <GenericValue> productAppls = delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productFeatureId", lowestFeatureId,"productFeatureApplTypeId","STANDARD_FEATURE"));
+ Iterator <GenericValue> pIter = productAppls.iterator();
+ boolean productFound = false;
+ nextProd: while(pIter.hasNext()) {
+ GenericValue productAppl = pIter.next();
+ fIter = selectedFeatures.iterator();
+ while (fIter.hasNext()) {
+ String featureId = fIter.next();
+ if (featureId.equals(lowestFeatureId)) continue;
+ Debug.log("===check for product: " + productAppl.getString("productId") + "===check for feature: " + featureId);
+ List <GenericValue> pAppls = delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productAppl.getString("productId"), "productFeatureId", featureId,"productFeatureApplTypeId","STANDARD_FEATURE"));
+ if (UtilValidate.isEmpty(pAppls)) {
+ continue nextProd;
+ }
+ }
+ productFound = true;
+ productId = productAppl.getString("productId");
+ break;
+ }
+
+ if (!productFound) {
+ request.setAttribute("_EVENT_MESSAGE_", "product variant could not be found.");
+ return "product";
+ }
+
+
+
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ }
+
+ // find the related variant.....
+
+ // if not found create it using the virt product and feature
+ // prices.
+
+ } else {
+ request.setAttribute("product_id", productId);
+ request.setAttribute("_EVENT_MESSAGE_",UtilProperties.getMessage(resource,"cart.addToCart.chooseVariationBeforeAddingToCart",locale));
+ return "product";
+ }
+ }
         
         // get the override price
         if (paramMap.containsKey("PRICE")) {
@@ -340,9 +441,7 @@
             if((paramMap.containsKey("accommodationMapId")) && (paramMap.containsKey("accommodationSpotId"))){
              accommodationMapId = (String) paramMap.remove("accommodationMapId");
              accommodationSpotId = (String) paramMap.remove("accommodationSpotId");
-
             }
-            
         }
 
         // get the quantity

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=645387&r1=645386&r2=645387&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Sun Apr  6 23:00:59 2008
@@ -2469,6 +2469,9 @@
       <relation type="one" fk-name="PROD_DEPTH_UOM" title="Depth" rel-entity-name="Uom">
         <key-map field-name="depthUomId" rel-field-name="uomId"/>
       </relation>
+      <relation type="one" fk-name="PROD_VVMETHOD_ENUM" title="VitualVariant Method" rel-entity-name="Enumeration">
+        <key-map field-name="virtualVariantMethodEnum" rel-field-name="enumId"/>
+      </relation>
       <relation type="one" fk-name="PROD_RATE_ENUM" title="Rating" rel-entity-name="Enumeration">
         <key-map field-name="ratingTypeEnum" rel-field-name="enumId"/>
       </relation>

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=645387&r1=645386&r2=645387&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 Sun Apr  6 23:00:59 2008
@@ -493,11 +493,10 @@
             GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
             if (product != null) {
                 List productAppls = null;
-                Map fields = UtilMisc.toMap("productFeatureApplTypeId", "SELECTABLE_FEATURE");
+                Map fields = UtilMisc.toMap("productId", product.getString("productId"), "productFeatureApplTypeId", "SELECTABLE_FEATURE");
                 List order = UtilMisc.toList("productFeatureTypeId","sequenceNum");
-                List features = product.getRelatedByAnd("ProductFeatureAppl", fields);
-                List featuresSorted = UtilMisc.sortMaps(features, order);
-                Iterator it = featuresSorted.iterator();
+                List features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order);
+                Iterator it = features.iterator();
                 String oldType = null;
                 while(it.hasNext()) {
                     GenericValue productFeatureAppl = (GenericValue) it.next();


Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r645387 - in /ofbiz/trunk/applications: order/config/OrderUiLabels.xml order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java product/entitydef/entitymodel.xml product/src/org/ofbiz/product/product/ProductWorker.java

Bilgin Ibryam
Hi Hans,

If I am not wrong the PROD_VVMETHOD_ENUM relation is added twice to Product entity.

Bilgin