|
Author: ashish
Date: Fri Jan 8 11:33:19 2010 New Revision: 897170 URL: http://svn.apache.org/viewvc?rev=897170&view=rev Log: Applied patch from jira issue - OFBIZ-3397- Advance Search should also support the feature base sorting. User should be able to sort on SIZE and COLORS kind of features associated with Products. This sort will be additional sort with ProductFields and ProductPrice. Here we need to add the additional sort not to change the existing. This will be achieve in the similar manner the ProductPrice in the ProductSearch.java and ProductSearchSession.java. Thanks Deepak & Rishi for the contribution. Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/AdvancedSearchOptions.groovy ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/advancedsearch.ftl Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/AdvancedSearchOptions.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/AdvancedSearchOptions.groovy?rev=897170&r1=897169&r2=897170&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/AdvancedSearchOptions.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/AdvancedSearchOptions.groovy Fri Jan 8 11:33:19 2010 @@ -26,6 +26,8 @@ import org.ofbiz.product.catalog.*; import org.ofbiz.product.feature.*; import org.ofbiz.product.product.*; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityOperator; searchCategoryId = parameters.SEARCH_CATEGORY_ID; if (!searchCategoryId) { @@ -36,6 +38,9 @@ productFeaturesByTypeMap = ParametricSearch.makeCategoryFeatureLists(searchCategoryId, delegator); productFeatureTypeIdsOrdered = new TreeSet(productFeaturesByTypeMap.keySet()) as List; +if(productFeatureTypeIdsOrdered) { + context.productFeatureTypes = delegator.findList("ProductFeatureType", EntityCondition.makeCondition("productFeatureTypeId", EntityOperator.IN, productFeatureTypeIdsOrdered), null, null, null, false); +} searchOperator = parameters.SEARCH_OPERATOR; if (!"AND".equals(searchOperator) && !"OR".equals(searchOperator)) { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=897170&r1=897169&r2=897170&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Fri Jan 8 11:33:19 2010 @@ -2094,6 +2094,55 @@ } } + public static class SortProductFeature extends ResultSortOrder { + protected String productFeatureTypeId; + protected boolean ascending; + + public SortProductFeature(String productFeatureTypeId, boolean ascending) { + this.productFeatureTypeId = productFeatureTypeId; + this.ascending = ascending; + } + + @Override + public void setSortOrder(ProductSearchContext productSearchContext) { + productSearchContext.dynamicViewEntity.addMemberEntity("PFAPPL", "ProductFeatureAndAppl"); + productSearchContext.dynamicViewEntity.addAlias("PFAPPL", "sortProductFeatureTypeId", "productFeatureTypeId", null, null, null, null); + productSearchContext.dynamicViewEntity.addAlias("PFAPPL", "sortProductFeatureId", "productFeatureId", null, null, null, null); + productSearchContext.dynamicViewEntity.addAlias("PFAPPL", "sortFromDate", "fromDate", null, null, null, null); + productSearchContext.dynamicViewEntity.addAlias("PFAPPL", "sortThruDate", "thruDate", null, null, null, null); + productSearchContext.dynamicViewEntity.addViewLink("PROD", "PFAPPL", Boolean.TRUE, UtilMisc.toList(new ModelKeyMap("productId", "productId"))); + productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortProductFeatureTypeId", EntityOperator.EQUALS, this.productFeatureTypeId)); + productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortFromDate", EntityOperator.LESS_THAN_EQUAL_TO, productSearchContext.nowTimestamp)); + productSearchContext.entityConditionList.add(EntityCondition.makeCondition( + EntityCondition.makeCondition("sortThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, + EntityCondition.makeCondition("sortThruDate", EntityOperator.GREATER_THAN_EQUAL_TO, productSearchContext.nowTimestamp))); + if (ascending) { + productSearchContext.orderByList.add("+sortProductFeatureId"); + } else { + productSearchContext.orderByList.add("-sortProductFeatureId"); + } + productSearchContext.fieldsToSelect.add("sortProductFeatureId"); + } + + @Override + public String getOrderName() { + return "ProductFeature:" + this.productFeatureTypeId; + } + + @Override + public String prettyPrintSortOrder(boolean detailed, Locale locale) { + String featureTypeName = null; + if (this.productFeatureTypeId != null) { + featureTypeName = this.productFeatureTypeId; + } + return featureTypeName; + } + + @Override + public boolean isAscending() { + return this.ascending; + } + } /** A rather large and verbose method that doesn't use the cool constraint and sort order objects */ /* public static ArrayList parametricKeywordSearchStandAlone(Set featureIdSet, String keywordsString, Delegator delegator, String productCategoryId, boolean includeSubCategories, String visitId, boolean anyPrefix, boolean anySuffix, boolean isAnd) { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?rev=897170&r1=897169&r2=897170&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Fri Jan 8 11:33:19 2010 @@ -828,6 +828,12 @@ } else if (sortOrder.startsWith("SPP:")) { String priceTypeId = sortOrder.substring("SPP:".length()); searchSetSortOrder(new ProductSearch.SortProductPrice(priceTypeId, ascending), session); + } else if (sortOrder.startsWith("SortProductFeature:")) { + String featureId = sortOrder.substring("SortProductFeature:".length()); + searchSetSortOrder(new ProductSearch.SortProductFeature(featureId, ascending), session); + } else if (sortOrder.startsWith("SPFT:")) { + String priceTypeId = sortOrder.substring("SPFT:".length()); + searchSetSortOrder(new ProductSearch.SortProductPrice(priceTypeId, ascending), session); } } @@ -1151,6 +1157,10 @@ ProductSearch.SortProductPrice spp = (ProductSearch.SortProductPrice) resultSortOrder; searchParamString.append("&S_O=SPP:"); searchParamString.append(spp.productPriceTypeId); + } else if (resultSortOrder instanceof ProductSearch.SortProductFeature) { + ProductSearch.SortProductFeature spf = (ProductSearch.SortProductFeature) resultSortOrder; + searchParamString.append("&S_O=SPFT:"); + searchParamString.append(spf.productFeatureTypeId); } searchParamString.append("&S_A="); searchParamString.append(resultSortOrder.isAscending() ? "Y" : "N"); Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/advancedsearch.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/advancedsearch.ftl?rev=897170&r1=897169&r2=897170&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/advancedsearch.ftl (original) +++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/catalog/advancedsearch.ftl Fri Jan 8 11:33:19 2010 @@ -73,6 +73,11 @@ <option value="SortProductField:averageCustomerRating">${uiLabelMap.ProductCustomerRating}</option> <option value="SortProductPrice:LIST_PRICE">${uiLabelMap.ProductListPrice}</option> <option value="SortProductPrice:DEFAULT_PRICE">${uiLabelMap.ProductDefaultPrice}</option> + <#if productFeatureTypes?exists && productFeatureTypes?has_content> + <#list productFeatureTypes as productFeatureType> + <option value="SortProductFeature:${productFeatureType.productFeatureTypeId}">${productFeatureType.description?default(productFeatureType.productFeatureTypeId)}</option> + </#list> + </#if> </select> ${uiLabelMap.EcommerceLowToHigh} <input type="radio" name="sortAscending" value="Y" checked="checked"/> ${uiLabelMap.EcommerceHighToLow} <input type="radio" name="sortAscending" value="N"/> |
| Free forum by Nabble | Edit this page |
