svn commit: r603164 - in /ofbiz/trunk/applications: ecommerce/data/DemoConfigurator.xml product/entitydef/entitymodel.xml product/src/org/ofbiz/product/config/ProductConfigWrapper.java

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

svn commit: r603164 - in /ofbiz/trunk/applications: ecommerce/data/DemoConfigurator.xml product/entitydef/entitymodel.xml product/src/org/ofbiz/product/config/ProductConfigWrapper.java

jleroux@apache.org
Author: jleroux
Date: Mon Dec 10 23:48:44 2007
New Revision: 603164

URL: http://svn.apache.org/viewvc?rev=603164&view=rev
Log:
A patch from Chris Lombardi "Need a better way to specify the default item configuration" (https://issues.apache.org/jira/browse/OFBIZ-1393) - OFBIZ-1393
One day we will have to change the PC001 options descriptions ;o)

Modified:
    ofbiz/trunk/applications/ecommerce/data/DemoConfigurator.xml
    ofbiz/trunk/applications/product/entitydef/entitymodel.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java

Modified: ofbiz/trunk/applications/ecommerce/data/DemoConfigurator.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/data/DemoConfigurator.xml?rev=603164&r1=603163&r2=603164&view=diff
==============================================================================
--- ofbiz/trunk/applications/ecommerce/data/DemoConfigurator.xml (original)
+++ ofbiz/trunk/applications/ecommerce/data/DemoConfigurator.xml Mon Dec 10 23:48:44 2007
@@ -33,7 +33,7 @@
     <ProductPrice productId="HD4GB_BRAND" productPricePurposeId="COMPONENT_PRICE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2004-08-20 12:55:36.479" price="420" createdDate="2004-08-20 12:55:36.479" createdByUserLogin="admin"/>
     <ProductPrice productId="ETH_BRAND" productPricePurposeId="COMPONENT_PRICE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2004-08-20 12:55:36.479" price="18" createdDate="2004-08-20 12:55:36.479" createdByUserLogin="admin"/>
     <ProductPrice productId="MOD_BRAND" productPricePurposeId="COMPONENT_PRICE" productPriceTypeId="DEFAULT_PRICE" currencyUomId="USD" productStoreGroupId="_NA_" fromDate="2004-08-20 12:55:36.479" price="15" createdDate="2004-08-20 12:55:36.479" createdByUserLogin="admin"/>
-    
+  
     <ProductConfigItem configItemId="IT0000" configItemTypeId="SINGLE" configItemName="RAM (brand)" description="Select the memory configuration:"/>
     <ProductConfigItem configItemId="IT0001" configItemTypeId="SINGLE" configItemName="HD (brand)" description="Select the Hard Disk:"/>
     <ProductConfigItem configItemId="IT0002" configItemTypeId="MULTIPLE" configItemName="PCI slot" description="Select the PCI cards:"/>
@@ -52,8 +52,8 @@
     <ProductConfigProduct configItemId="IT0002" configOptionId="OP004" productId="ETH_BRAND" quantity="1"/>
     <ProductConfigProduct configItemId="IT0002" configOptionId="OP005" productId="MOD_BRAND" quantity="1"/>
     
-    <ProductConfig productId="PC001" configItemId="IT0000" sequenceNum="10" fromDate="2004-08-20 12:59:26.209" configTypeId="QUESTION" isMandatory="Y"/>
-    <ProductConfig productId="PC001" configItemId="IT0001" sequenceNum="20" fromDate="2004-08-20 12:59:26.209" description="1st Hard Disk drive" configTypeId="QUESTION" isMandatory="Y"/>
+    <ProductConfig productId="PC001" configItemId="IT0000" sequenceNum="10" fromDate="2004-08-20 12:59:26.209" configTypeId="QUESTION" defaultConfigOptionId="OP001" isMandatory="Y"/>
+    <ProductConfig productId="PC001" configItemId="IT0001" sequenceNum="20" fromDate="2004-08-20 12:59:26.209" description="1st Hard Disk drive" defaultConfigOptionId="OP003" configTypeId="QUESTION" isMandatory="Y"/>
     <ProductConfig productId="PC001" configItemId="IT0001" sequenceNum="30" fromDate="2004-08-20 12:59:26.209" description="2nd Hard Disk drive" configTypeId="QUESTION" isMandatory="N"/>
     <ProductConfig productId="PC001" configItemId="IT0002" sequenceNum="40" fromDate="2004-08-20 12:59:26.209" configTypeId="QUESTION" isMandatory="N"/>
     

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=603164&r1=603163&r2=603164&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Mon Dec 10 23:48:44 2007
@@ -552,6 +552,7 @@
         <field name="description" type="description"></field>
         <field name="longDescription" type="very-long"></field>
         <field name="configTypeId" type="id"></field>
+        <field name="defaultConfigOptionId" type="id"></field>
         <field name="thruDate" type="date-time"></field>
         <field name="isMandatory" type="indicator"></field>
         <prim-key field="productId"/>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java?rev=603164&r1=603163&r2=603164&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java Mon Dec 10 23:48:44 2007
@@ -125,8 +125,11 @@
         for (int i = 0; i < questions.size(); i++) {
             ConfigItem ci = (ConfigItem)questions.get(i);
             if (ci.isMandatory()) {
-                if (ci.getOptions().size() > 0) {
-                    ConfigOption co = (ConfigOption)ci.getOptions().get(0);
+                ConfigOption co = ci.getDefault();
+                if(co != null){
+                    co.setSelected(true);
+                }else if (ci.getOptions().size() > 0) {
+                    co = (ConfigOption)ci.getOptions().get(0);
                     co.setSelected(true);
                 }
             }
@@ -303,7 +306,7 @@
         public List getOptions() {
             return options;
         }
-        
+                
         public String getQuestion() {
             String question = "";
             if (UtilValidate.isNotEmpty(configItemAssoc.getString("description"))) {
@@ -355,6 +358,19 @@
             return null;
         }
         
+        public ConfigOption getDefault(){
+            String defaultConfigOptionId = configItemAssoc.getString("defaultConfigOptionId");
+            if(UtilValidate.isNotEmpty(defaultConfigOptionId)){
+                for(ConfigOption oneOption : (List<ConfigOption>)getOptions()) {
+                    String currentConfigOptionId = oneOption.getId();
+                    if (defaultConfigOptionId.compareToIgnoreCase(currentConfigOptionId) == 0  ){
+                        return oneOption;
+                    }
+                }
+            }
+            return null;
+        }
+        
         public boolean equals(Object obj) {
             if (obj == null || !(obj instanceof ConfigItem)) {
                 return false;
@@ -436,6 +452,10 @@
 
         public String getDescription() {
             return (configOption.getString("description") != null? configOption.getString("description"): "no description");
+        }
+        
+        public String getId(){
+            return configOption.getString("configOptionId");
         }
         
         public double getPrice() {