Author: hansbak
Date: Thu Apr 3 01:33:50 2008 New Revision: 644221 URL: http://svn.apache.org/viewvc?rev=644221&view=rev Log: partial implementation of the new Variant selection method. Renamed the selection on the product using the enumeration entity, added some productworker methods. As long as not selected on the product, the current functions of the system are not changed. Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl ofbiz/trunk/applications/product/data/ProductTypeData.xml ofbiz/trunk/applications/product/entitydef/entitymodel.xml ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml 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=644221&r1=644220&r2=644221&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 Thu Apr 3 01:33:50 2008 @@ -234,9 +234,21 @@ //Check for virtual products if (ProductWorker.isVirtual(delegator, productId)) { - 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))) { + // 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"; + } } // get the override price Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh?rev=644221&r1=644220&r2=644221&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/productdetail.bsh Thu Apr 3 01:33:50 2008 @@ -241,6 +241,9 @@ // Special Variant Code if ("Y".equals(product.getString("isVirtual"))) { + if ("VV_FEATURETREE".equals(ProductWorker.getProductvirtualVariantMethod(delegator, productId))) { + context.put("featureLists", ProductWorker.getProductFeaturesByTypesAndSeq(product)); + } else { featureMap = dispatcher.runSync("getProductFeatureSet", UtilMisc.toMap("productId", productId)); featureSet = featureMap.get("featureSet"); if (featureSet != null && featureSet.size() > 0) { @@ -413,6 +416,7 @@ context.put("virtualJavaScript", jsBuf.toString()); } } + } } // get product associations Modified: ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl?rev=644221&r1=644220&r2=644221&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/entry/catalog/productdetail.ftl Thu Apr 3 01:33:50 2008 @@ -229,6 +229,28 @@ document.addToShoppingList.submit(); </#if> } + + <#if product.virtualVariantMethodEnum?if_exists == "VV_FEATURETREE" && featureLists?has_content> + function checkRadioButton() { + //alert("work"); + var block = document.getElementById("addCart"); + + <#list featureLists as featureList> + <#list featureList as feature> + <#if feature_index == 0> + var myList = document.getElementById("FT${feature.productFeatureTypeId}"); + if (myList.options[0].selected == true){ + block.style.display = "none"; + return; + } + + <#break> + </#if> + </#list> + </#list> + block.style.display = "block"; + } + </#if> //--> </script> @@ -396,6 +418,27 @@ <#assign inStock = true> <#-- Variant Selection --> <#if product.isVirtual?if_exists?upper_case == "Y"> + <#if product.virtualVariantMethodEnum?if_exists == "VV_FEATURETREE" && featureLists?has_content> + <#list featureLists as featureList> + <#list featureList as feature> + <#if feature_index == 0> + <div class="tabletext">${feature.description}: <select id="FT${feature.productFeatureTypeId}" name="FT${feature.productFeatureTypeId}" onChange="javascript:checkRadioButton();"> + <option value="select" selected="selected"> select option </option> + <#else> + <option value="${feature.productFeatureId}">${feature.description}</option> + </#if> + </#list> + </select> + </div> + </#list> + <input type="hidden" name="add_product_id" value="${product.productId}"/> + <div id="addCart" style="display:none;> + <span style="white-space: nowrap;"><b>${uiLabelMap.CommonQuantity}:</b></span> + <input type="text" class="inputBox" size="5" name="quantity" value="1"/> + <a href="javascript:document.addform.submit();" class="buttontext"><span style="white-space: nowrap;">${uiLabelMap.EcommerceAddtoCart}</span></a> + + </div> + </#if> <#if variantTree?exists && (variantTree.size() > 0)> <#list featureSet as currentType> <div class="tabletext"> Modified: ofbiz/trunk/applications/product/data/ProductTypeData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/data/ProductTypeData.xml?rev=644221&r1=644220&r2=644221&view=diff ============================================================================== --- ofbiz/trunk/applications/product/data/ProductTypeData.xml (original) +++ ofbiz/trunk/applications/product/data/ProductTypeData.xml Thu Apr 3 01:33:50 2008 @@ -383,7 +383,11 @@ <Enumeration description="Min Rating" enumCode="MIN" enumId="PRDR_MIN" sequenceId="01" enumTypeId="PROD_RATING_TYPE"/> <Enumeration description="Max Rating" enumCode="MAX" enumId="PRDR_MAX" sequenceId="02" enumTypeId="PROD_RATING_TYPE"/> <Enumeration description="Rating Override" enumCode="FLAT" enumId="PRDR_FLAT" sequenceId="03" enumTypeId="PROD_RATING_TYPE"/> - + + <EnumerationType description="Virtual Variant Method" enumTypeId="PROD_VVMETHOD" hasTable="N" parentTypeId=""/> + <Enumeration description="Feature tree Generation" enumCode="FEATURETREE" enumId="VV_FEATURETREE" sequenceId="01" enumTypeId="PROD_VVMETHOD"/> + <Enumeration description="Variant Tree generation" enumCode="VARIANTTREE" enumId="VV_VARIANTTREE" sequenceId="02" enumTypeId="PROD_VVMETHOD"/> + <ProductPriceType description="List Price" productPriceTypeId="LIST_PRICE"/> <ProductPriceType description="Default Price" productPriceTypeId="DEFAULT_PRICE"/> <ProductPriceType description="Average Cost" productPriceTypeId="AVERAGE_COST"/> Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=644221&r1=644220&r2=644221&view=diff ============================================================================== --- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Thu Apr 3 01:33:50 2008 @@ -2422,7 +2422,7 @@ <field name="includeInPromotions" type="indicator"></field> <field name="isVirtual" type="indicator"></field> <field name="isVariant" type="indicator"></field> - <field name="newVirtualVariantMethod" type="indicator"><description>If this field is set to 'Y', the new feature variant selection method will be used, other values will use the old method</description></field> + <field name="virtualVariantMethodEnum" type="id"><description>This field defines the method of selecting a variant from the selectable features on the virtual product. Either as a variant explosion which will work to about 200 variants or as feature explosion which almost has no limits</description></field> <field name="originGeoId" type="id"></field> <field name="requirementMethodEnumId" type="id"></field> <field name="billOfMaterialLevel" type="numeric"></field> @@ -2471,6 +2471,9 @@ </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> + <relation type="one" fk-name="PROD_VVMETHOD_ENUM" title="Virtual-Variant Method" rel-entity-name="Enumeration"> + <key-map field-name="virtualVariantMethodEnum" rel-field-name="enumId"/> </relation> <relation type="one" fk-name="PROD_RQMT_ENUM" title="RequirementMethod" rel-entity-name="Enumeration"> <key-map field-name="requirementMethodEnumId" rel-field-name="enumId"/> 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=644221&r1=644220&r2=644221&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 Thu Apr 3 01:33:50 2008 @@ -479,6 +479,106 @@ } return features; } + /** + * + * @param product + * @return list of featureTypes sorted by sequence for this product. + */ + public static List getProductFeatureTypesBySeq(GenericDelegator delegator, String productId) { + if (productId == null) { + return null; + } + List featureTypes = new ArrayList(); + try { + GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + if (product != null) { + List productAppls = null; + Map fields = UtilMisc.toMap("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(); + String oldType = null; + while(it.hasNext()) { + GenericValue productFeatureAppl = (GenericValue) it.next(); + if (oldType == null || !oldType.equals(productFeatureAppl.getString("productFeatureTypeId"))) { + featureTypes.add(productFeatureAppl.getString("productFeatureTypeId")); + oldType = productFeatureAppl.getString("productFeatureTypeId"); + } + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + return featureTypes; + } + + public static String getProductvirtualVariantMethod(GenericDelegator delegator, String productId) { + GenericValue product = null; + try { + product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + + if (product != null) { + return product.getString("virtualVariantMethodEnum"); + } else { + return null; + } + } + + /** + * + * @param product + * @return list featureType and related features for this product ordered by type and sequence + */ + public static List getProductFeaturesByTypesAndSeq(GenericValue product) { + if (product == null) { + return null; + } + List featureTypeFeatures = new ArrayList(); + try { + if (product != null) { + GenericDelegator delegator = product.getDelegator(); + List productAppls = null; + Map fields = UtilMisc.toMap("productId", product.getString("productId"), "productFeatureApplTypeId", "SELECTABLE_FEATURE"); + List order = UtilMisc.toList("productFeatureTypeId","sequenceNum"); + List features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order); + List featuresSorted = UtilMisc.sortMaps(features, order); + Iterator it = featuresSorted.iterator(); + String oldType = null; + List featureList = new LinkedList(); + while(it.hasNext()) { + GenericValue productFeatureAppl = (GenericValue) it.next(); + if (oldType == null || !oldType.equals(productFeatureAppl.getString("productFeatureTypeId"))) { + if (oldType != null) { + featureTypeFeatures.add(featureList); + featureList = new LinkedList(); + Debug.log("=====add feature: " + oldType); + } + GenericValue productFeatureType = delegator.findByPrimaryKey("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", + productFeatureAppl.getString("productFeatureTypeId"))); + featureList.add(UtilMisc.toMap("productFeatureTypeId", productFeatureAppl.getString("productFeatureTypeId"), + "description", productFeatureType.getString("description"))); + oldType = productFeatureAppl.getString("productFeatureTypeId"); + } + // featureId and description + featureList.add(UtilMisc.toMap("productFeatureId", productFeatureAppl.getString("productFeatureId"), "description", productFeatureAppl.getString("description"))); + } + if (oldType != null) { + // last map + featureTypeFeatures.add(featureList); + Debug.log("=====add feature: " + oldType); + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + Debug.log("=====total list: " + featureTypeFeatures.toString()); + + return featureTypeFeatures; + } public static Map getOptionalProductFeatures(GenericDelegator delegator, String productId) { Map featureMap = new LinkedHashMap(); Modified: ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml?rev=644221&r1=644220&r2=644221&view=diff ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml (original) +++ ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml Thu Apr 3 01:33:50 2008 @@ -35,21 +35,26 @@ <field use-when="product==null&&productId==null" name="productId" title="${uiLabelMap.ProductProductId}"><text size="20" maxlength="20"/></field> <field use-when="product==null&&productId!=null" name="productId" title="${uiLabelMap.ProductProductId}" tooltip="${uiLabelMap.ProductNotFindProductId} [${productId}]"><text size="20" maxlength="20"/></field> - <field position="1" name="isVirtual" title="${uiLabelMap.ProductVirtualProduct}"> - <drop-down><option key="N" description="${uiLabelMap.CommonN}"/><option key="Y" description="${uiLabelMap.CommonY}"/></drop-down> - </field> - <field position="2" name="isVariant" title="${uiLabelMap.ProductVariantProduct}"> - <drop-down><option key="N" description="${uiLabelMap.CommonN}"/><option key="Y" description="${uiLabelMap.CommonY}"/></drop-down> - </field> - <field position="3" name="newVirtualVariantMethod" title="${uiLabelMap.ProductNewVirtualVariantMethod}"> - <drop-down><option key="N" description="${uiLabelMap.CommonN}"/><option key="Y" description="${uiLabelMap.CommonY}"/></drop-down> - </field> <field name="productTypeId" title="${uiLabelMap.ProductProductType}"> <drop-down no-current-selected-key="FINISHED_GOOD"> <entity-options entity-name="ProductType" description="${description}"> <!-- [${productTypeId}] --> <entity-order-by field-name="description"/> </entity-options> </drop-down> + </field> + <field position="2" name="virtualVariantMethodEnum" title="${uiLabelMap.ProductVirtualVariantMethod}"> + <drop-down allow-empty="true"> + <entity-options entity-name="Enumeration" key-field-name="enumId" description="${description}"> + <entity-constraint name="enumTypeId" value="PROD_VVMETHOD"/> + <entity-order-by field-name="sequenceId"/> + </entity-options> + </drop-down> + </field> + <field position="1" name="isVirtual" title="${uiLabelMap.ProductVirtualProduct}"> + <drop-down><option key="N" description="${uiLabelMap.CommonN}"/><option key="Y" description="${uiLabelMap.CommonY}"/></drop-down> + </field> + <field position="2" name="isVariant" title="${uiLabelMap.ProductVariantProduct}"> + <drop-down><option key="N" description="${uiLabelMap.CommonN}"/><option key="Y" description="${uiLabelMap.CommonY}"/></drop-down> </field> <field name="primaryProductCategoryId" title="${uiLabelMap.ProductPrimaryCategory}"> <drop-down allow-empty="true"> |
Free forum by Nabble | Edit this page |