diff --git a/applications/product/src/org/ofbiz/product/product/ProductSearch.java b/applications/product/src/org/ofbiz/product/product/ProductSearch.java index 4bd36c7352..019c8a06ec 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductSearch.java +++ b/applications/product/src/org/ofbiz/product/product/ProductSearch.java @@ -1866,6 +1866,49 @@ public class ProductSearch { } } + public static class ProductFieldConstraint extends ProductSearchConstraint { + public static final String constraintName = "ProductField"; + protected String keyword; + protected String productFieldName; + + public ProductFieldConstraint(String keyword, String productFieldName) { + this.keyword = keyword; + this.productFieldName = productFieldName; + } + + @Override + public void addConstraint(ProductSearchContext productSearchContext) { + productSearchContext.dynamicViewEntity.addAlias("PROD", productFieldName, null, null, null, null, null); + productSearchContext.entityConditionList.add(EntityCondition.makeCondition(productFieldName ,EntityOperator.LIKE, keyword + "%")); + productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.keyword))); + } + + @Override + public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) { + return UtilProperties.getMessage(resource, "ProductKeywords", locale); + } + + @Override + public boolean equals(Object obj) { + ProductSearchConstraint psc = (ProductSearchConstraint) obj; + if (psc instanceof ProductFieldConstraint) { + ProductFieldConstraint that = (ProductFieldConstraint) psc; + if (this.keyword == null) { + if (that.keyword != null) { + return false; + } + } else { + if (!this.keyword.equals(that.keyword)) { + return false; + } + } + return true; + } else { + return false; + } + } + } + // ====================================================================== // Result Sort Classes // ====================================================================== diff --git a/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java b/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java index f125d897d5..5f15d21ba3 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java +++ b/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java @@ -42,6 +42,7 @@ import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; @@ -87,7 +88,9 @@ public class ProductSearchSession { /** Basic copy constructor */ public ProductSearchOptions(ProductSearchOptions productSearchOptions) { this.constraintList = FastList.newInstance(); - this.constraintList.addAll(productSearchOptions.constraintList); + if (UtilValidate.isNotEmpty(productSearchOptions.constraintList)) { + this.constraintList.addAll(productSearchOptions.constraintList); + } this.topProductCategoryId = productSearchOptions.topProductCategoryId; this.resultSortOrder = productSearchOptions.resultSortOrder; this.viewIndex = productSearchOptions.viewIndex; @@ -593,6 +596,20 @@ public class ProductSearchSession { constraintsChanged = true; } + // if productName were specified, add a constraint for them + if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_PRODUCT_NAME"))) { + String productName = (String) parameters.get("SEARCH_PRODUCT_NAME"); + searchAddConstraint(new ProductSearch.ProductFieldConstraint(productName, "productName"), session); + constraintsChanged = true; + } + + // if internalName were specified, add a constraint for them + if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_INTERNAL_PROD_NAME"))) { + String internalName = (String) parameters.get("SEARCH_INTERNAL_PROD_NAME"); + searchAddConstraint(new ProductSearch.ProductFieldConstraint(internalName, "internalName"), session); + constraintsChanged = true; + } + for (int kwNum = 1; kwNum < 10; kwNum++) { if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_STRING" + kwNum))) { String keywordString = (String) parameters.get("SEARCH_STRING" + kwNum); @@ -862,8 +879,13 @@ public class ProductSearchSession { List productIds = FastList.newInstance(); String visitId = VisitHandler.getVisitId(session); List productSearchConstraintList = ProductSearchOptions.getConstraintList(session); - // if no constraints, don't do a search... - if (UtilValidate.isNotEmpty(productSearchConstraintList)) { + Map requestParams = UtilHttp.getParameterMap(request); + String noConditionFind = (String) requestParams.get("noConditionFind"); + if (UtilValidate.isEmpty(noConditionFind)) { + noConditionFind = UtilProperties.getPropertyValue("widget", "widget.defaultNoConditionFind"); + } + // if noConditionFind to Y then find without conditions otherwise search according to constraints. + if ("Y".equals(noConditionFind) || UtilValidate.isNotEmpty(productSearchConstraintList)) { // if the search options have changed since the last search, put at the beginning of the options history list checkSaveSearchOptionsHistory(session); @@ -914,7 +936,9 @@ public class ProductSearchSession { ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(request); ProductSearchContext productSearchContext = new ProductSearchContext(delegator, visitId); - productSearchContext.addProductSearchConstraints(productSearchConstraintList); + if (UtilValidate.isNotEmpty(productSearchConstraintList)) { + productSearchContext.addProductSearchConstraints(productSearchConstraintList); + } productSearchContext.setResultSortOrder(resultSortOrder); productSearchContext.setResultOffset(resultOffset); productSearchContext.setMaxResults(maxResults); @@ -951,6 +975,7 @@ public class ProductSearchSession { result.put("previousViewSize", previousViewSize); result.put("searchConstraintStrings", searchConstraintStrings); result.put("searchSortOrderString", searchSortOrderString); + result.put("noConditionFind", noConditionFind); return result; } @@ -962,6 +987,9 @@ public class ProductSearchSession { StringBuilder searchParamString = new StringBuilder(); List constraintList = productSearchOptions.getConstraintList(); + if (UtilValidate.isEmpty(constraintList)) { + constraintList = new ArrayList(); + } int categoriesCount = 0; int featuresCount = 0; int featureCategoriesCount = 0; diff --git a/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy b/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy index 13be5ad5a5..b9fc27fe9c 100644 --- a/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy +++ b/applications/product/webapp/catalog/WEB-INF/actions/find/keywordsearch.groovy @@ -38,6 +38,7 @@ productCategories = delegator.findList("ProductCategory", expr, null, ['descript context.applicationTypes = applicationTypes; context.productCategories = productCategories; +context.noConditionFind = result.noConditionFind; context.productIds = result.productIds; context.viewIndex = result.viewIndex; context.viewSize = result.viewSize; diff --git a/applications/product/webapp/catalog/find/advancedsearch.ftl b/applications/product/webapp/catalog/find/advancedsearch.ftl index 5adf501331..e86bca6714 100644 --- a/applications/product/webapp/catalog/find/advancedsearch.ftl +++ b/applications/product/webapp/catalog/find/advancedsearch.ftl @@ -24,6 +24,7 @@ under the License.
+ <#if searchCategory?has_content> @@ -77,6 +78,26 @@ under the License. + + + + + + + + @@ -120,18 +120,18 @@ under the License.
+ ${uiLabelMap.ProductProductName}: + +
+ +
+
+ ${uiLabelMap.ProductInternalName}: + +
+ +
+
${uiLabelMap.ProductKeywords}: diff --git a/applications/product/webapp/catalog/find/keywordsearch.ftl b/applications/product/webapp/catalog/find/keywordsearch.ftl index 13ba7e22ad..72c9f479ca 100644 --- a/applications/product/webapp/catalog/find/keywordsearch.ftl +++ b/applications/product/webapp/catalog/find/keywordsearch.ftl @@ -73,18 +73,18 @@ under the License. <#if 0 < viewIndex?int> - ${uiLabelMap.CommonPrevious} | + ${uiLabelMap.CommonPrevious} | <#if 0 < listSize?int> ${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize} <#if highIndex?int < listSize?int> - | ${uiLabelMap.CommonNext} + | ${uiLabelMap.CommonNext} <#if paging == "Y"> - ${uiLabelMap.CommonPagingOff} + ${uiLabelMap.CommonPagingOff} <#else> - ${uiLabelMap.CommonPagingOn} + ${uiLabelMap.CommonPagingOn} <#if 0 < viewIndex?int> - ${uiLabelMap.CommonPrevious} | + ${uiLabelMap.CommonPrevious} | <#if 0 < listSize?int> ${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize} <#if highIndex?int < listSize?int> - | ${uiLabelMap.CommonNext} + | ${uiLabelMap.CommonNext} <#if paging == "Y"> - ${uiLabelMap.CommonPagingOff} + ${uiLabelMap.CommonPagingOff} <#else> - ${uiLabelMap.CommonPagingOn} + ${uiLabelMap.CommonPagingOn}