svn commit: r531362 - in /ofbiz/trunk: applications/product/config/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/find/ framework/common/config/

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

svn commit: r531362 - in /ofbiz/trunk: applications/product/config/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/find/ framework/common/config/

jacopoc
Author: jacopoc
Date: Mon Apr 23 00:33:53 2007
New Revision: 531362

URL: http://svn.apache.org/viewvc?view=rev&rev=531362
Log:
Added a new search parameter to specify a category whose member products will always be added to the beginning of the search result list (ordered by sequenceNum, filtered by from/thru dates).

Modified:
    ofbiz/trunk/applications/product/config/ProductUiLabels.properties
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java
    ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl
    ofbiz/trunk/framework/common/config/CommonUiLabels.properties

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.properties?view=diff&rev=531362&r1=531361&r2=531362
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels.properties (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels.properties Mon Apr 23 00:33:53 2007
@@ -975,6 +975,7 @@
 ProductPrimaryParentCategory=Primary Parent Category
 ProductPrimaryParentGroup=Primary Parent Group
 ProductPrimaryShipGroupSeqId=Primary Ship Group Seq Id
+ProductPrioritizeProductsinCategory=Prioritize Products in Category
 ProductProdCatContentTypeId=Prod Cat Content Type Id
 ProductProduct=Product
 ProductProductATP=Product ATP

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?view=diff&rev=531362&r1=531361&r2=531362
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Mon Apr 23 00:33:53 2007
@@ -28,6 +28,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.sql.Timestamp;
+
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -37,6 +39,7 @@
 import javolution.util.FastList;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
@@ -45,6 +48,11 @@
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityFindOptions;
+import org.ofbiz.entity.util.EntityListIterator;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.product.catalog.CatalogWorker;
 import org.ofbiz.product.category.CategoryWorker;
@@ -67,6 +75,7 @@
 
     public static class ProductSearchOptions implements java.io.Serializable {
         protected List constraintList = null;
+        protected String topProductCategoryId = null;
         protected ResultSortOrder resultSortOrder = null;
         protected Integer viewIndex = null;
         protected Integer viewSize = null;
@@ -78,6 +87,7 @@
         public ProductSearchOptions(ProductSearchOptions productSearchOptions) {
             this.constraintList = FastList.newInstance();
             this.constraintList.addAll(productSearchOptions.constraintList);
+            this.topProductCategoryId = productSearchOptions.topProductCategoryId;
             this.resultSortOrder = productSearchOptions.resultSortOrder;
             this.viewIndex = productSearchOptions.viewIndex;
             this.viewSize = productSearchOptions.viewSize;
@@ -121,6 +131,7 @@
         public static void clearSearchOptions(HttpSession session) {
             ProductSearchOptions productSearchOptions = getProductSearchOptions(session);
             productSearchOptions.constraintList = null;
+            productSearchOptions.topProductCategoryId = null;
             productSearchOptions.resultSortOrder = null;
         }
         
@@ -187,6 +198,29 @@
             }
         }
 
+        public String getTopProductCategoryId() {
+            return topProductCategoryId;
+        }
+
+        public static void setTopProductCategoryId(String topProductCategoryId, HttpSession session) {
+            ProductSearchOptions productSearchOptions = getProductSearchOptions(session);
+            productSearchOptions.setTopProductCategoryId(topProductCategoryId);
+        }
+
+        public void setTopProductCategoryId(String topProductCategoryId) {
+            if (this.topProductCategoryId != null && topProductCategoryId != null) {
+                if (!this.topProductCategoryId.equals(topProductCategoryId)) {
+                    this.topProductCategoryId = topProductCategoryId;
+                    this.changed = true;
+                }
+            } else {
+                if (this.topProductCategoryId != null || topProductCategoryId != null) {
+                    this.topProductCategoryId = topProductCategoryId;
+                    this.changed = true;
+                }
+            }
+        }
+
         public List searchGetConstraintStrings(boolean detailed, GenericDelegator delegator, Locale locale) {
             List productSearchConstraintList = this.getConstraintList();
             List constraintStrings = FastList.newInstance();
@@ -458,6 +492,12 @@
             }
         }
 
+        if (UtilValidate.isNotEmpty((String) parameters.get("PRIORITIZE_CATEGORY_ID"))) {
+            String prioritizeCategoryId = (String) parameters.get("PRIORITIZE_CATEGORY_ID");
+            ProductSearchOptions.setTopProductCategoryId(prioritizeCategoryId, session);
+            constraintsChanged = true;
+        }
+
         // if there is another category, add a constraint for it
         if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_CATEGORY_ID"))) {
             String searchCategoryId = (String) parameters.get("SEARCH_CATEGORY_ID");
@@ -725,6 +765,7 @@
         HttpSession session = request.getSession();
         ProductSearchOptions productSearchOptions = getProductSearchOptions(session);
         
+        String addOnTopProdCategoryId = productSearchOptions.getTopProductCategoryId();
         Integer viewIndexInteger = productSearchOptions.getViewIndex();
         if (viewIndexInteger != null) viewIndex = viewIndexInteger.intValue();
         Integer viewSizeInteger = productSearchOptions.getViewSize();
@@ -733,12 +774,8 @@
         lowIndex = viewIndex * viewSize;
         highIndex = (viewIndex + 1) * viewSize;
 
-        // setup resultOffset and maxResults, noting that resultOffset is 1 based, not zero based as these numbers
-        Integer resultOffset = new Integer(lowIndex + 1);
-        Integer maxResults = new Integer(viewSize);
-
         // ========== Do the actual search
-        ArrayList productIds = null;
+        List productIds = FastList.newInstance();
         String visitId = VisitHandler.getVisitId(session);
         List productSearchConstraintList = ProductSearchOptions.getConstraintList(session);
         // if no constraints, don't do a search...
@@ -746,6 +783,52 @@
             // if the search options have changed since the last search, put at the beginning of the options history list
             checkSaveSearchOptionsHistory(session);
 
+            int addOnTopTotalListSize = 0;
+            int addOnTopListSize = 0;
+            List addOnTopProductCategoryMembers = FastList.newInstance();
+            if (UtilValidate.isNotEmpty(addOnTopProdCategoryId)) {
+                // always include the members of the addOnTopProdCategoryId
+                Timestamp now = UtilDateTime.nowTimestamp();
+                List addOnTopProdCondList = FastList.newInstance();
+                addOnTopProdCondList.add(new EntityExpr(new EntityExpr("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("thruDate", EntityOperator.GREATER_THAN, now)));
+                addOnTopProdCondList.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN, now));
+                addOnTopProdCondList.add(new EntityExpr("productCategoryId", EntityOperator.EQUALS, addOnTopProdCategoryId));
+                EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
+                EntityListIterator pli = null;
+                try {
+                    pli = delegator.findListIteratorByCondition("ProductCategoryMember", new EntityConditionList(addOnTopProdCondList, EntityOperator.AND), null, UtilMisc.toList("productId"), UtilMisc.toList("sequenceNum"), findOpts);
+                    addOnTopProductCategoryMembers = pli.getPartialList(lowIndex, viewSize);
+                    addOnTopListSize = addOnTopProductCategoryMembers.size();
+                    for (int i = 0; i < addOnTopProductCategoryMembers.size(); i++) {
+                        GenericValue alwaysAddProductCategoryMember = (GenericValue)addOnTopProductCategoryMembers.get(i);
+                        productIds.add(alwaysAddProductCategoryMember.getString("productId"));
+                    }
+                    // attempt to get the full size
+                    pli.last();
+                    addOnTopTotalListSize = pli.currentIndex();
+                    listSize = listSize + addOnTopTotalListSize;
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                } finally {
+                    if (pli != null) {
+                        try {
+                            pli.close();
+                        } catch (GenericEntityException e) {
+                            Debug.logError(e, module);
+                        }
+                    }
+                }
+            }
+
+            // setup resultOffset and maxResults, noting that resultOffset is 1 based, not zero based as these numbers
+            int resultOffsetInt = lowIndex - addOnTopTotalListSize + 1;
+            if (resultOffsetInt < 1) {
+                resultOffsetInt = 1;
+            }
+            int maxResultsInt = viewSize - addOnTopListSize;
+            Integer resultOffset = new Integer(resultOffsetInt);
+            Integer maxResults = new Integer(maxResultsInt);
+
             ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(request);
 
             ProductSearchContext productSearchContext = new ProductSearchContext(delegator, visitId);
@@ -754,11 +837,14 @@
             productSearchContext.setResultOffset(resultOffset);
             productSearchContext.setMaxResults(maxResults);
 
-            productIds = productSearchContext.doSearch();
+            List foundProductIds = productSearchContext.doSearch();
+            if (maxResultsInt > 0) {
+                productIds.addAll(foundProductIds);
+            }
 
             Integer totalResults = productSearchContext.getTotalResults();
             if (totalResults != null) {
-                listSize = totalResults.intValue();
+                listSize = listSize + totalResults.intValue();
             }
         }
 

Modified: ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl?view=diff&rev=531362&r1=531361&r2=531362
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl Mon Apr 23 00:33:53 2007
@@ -231,6 +231,15 @@
         </div>
       </td>
     </tr>
+    <tr>
+      <td align="right" valign="middle">
+        ${uiLabelMap.ProductPrioritizeProductsinCategory}:
+      </td>
+      <td valign="middle">
+        <input type="text" class="inputBox" name="PRIORITIZE_CATEGORY_ID" size="20" maxlength="20" value="${requestParameters.PRIORITIZE_CATEGORY_ID?if_exists}"/>
+        <a href="javascript:call_fieldlookup2(document.advtokeywordsearchform.PRIORITIZE_CATEGORY_ID,'LookupProductCategory');"><img src='/images/fieldlookup.gif' width='15' height='14' border='0' alt='Click here For Field Lookup'/></a>
+      </td>
+    </tr>
     <#if searchConstraintStrings?has_content>
       <tr>
         <td align="right" valign="top">

Modified: ofbiz/trunk/framework/common/config/CommonUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels.properties?view=diff&rev=531362&r1=531361&r2=531362
==============================================================================
--- ofbiz/trunk/framework/common/config/CommonUiLabels.properties (original)
+++ ofbiz/trunk/framework/common/config/CommonUiLabels.properties Mon Apr 23 00:33:53 2007
@@ -37,7 +37,7 @@
 CommonAllMethods=All methods
 CommonAllWeek=All Week
 CommonAllowSolicitation=(allow solicitation?)
-CommonAlwaysInclude=AlwaysInclude
+CommonAlwaysInclude=Always Include
 CommonAmount=Amount
 CommonAnd=And
 CommonAny=Any