You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by as...@apache.org on 2014/10/18 13:23:46 UTC

svn commit: r1632760 - in /ofbiz/branches/release13.07/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ order/webapp/ordermgr/entry/catalog/ product/servicedef/ product/src/org/ofbiz/product/category/ product/src/org/ofbiz/product/pro...

Author: ashish
Date: Sat Oct 18 11:23:45 2014
New Revision: 1632760

URL: http://svn.apache.org/r1632760
Log:
Applied bug fix from trunk r1632750.
===========================================
Applied patch from jira issue - OFBIZ-4528 - Out of stock products screw up the pagination during category browsing.
===================================================================
Pagination is handled in getProductCategoryAndLimitedMembers
Then the out of stock filtering is done in CategoryDetail.groovy.
Hence the pagination is screwed up. Certain pages might show less records or no records based upon data condition.
===================================================================
Thanks Arun for the contribution and Thanks Kiran for creating the issue.

Modified:
    ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
    ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
    ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
    ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
    ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java

Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy?rev=1632760&r1=1632759&r2=1632760&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy (original)
+++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy Sat Oct 18 11:23:45 2014
@@ -54,52 +54,20 @@ andMap = [productCategoryId : productCat
         limitView : limitView];
 andMap.put("prodCatalogId", currentCatalogId);
 andMap.put("checkViewAllow", true);
+// Prevents out of stock product to be displayed on site
+productStore = ProductStoreWorker.getProductStore(request);
+if (productStore) {
+    andMap.put("productStoreId", productStore.productStoreId);
+}
 if (context.orderByFields) {
     andMap.put("orderByFields", context.orderByFields);
 } else {
     andMap.put("orderByFields", ["sequenceNum", "productId"]);
 }
 catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers", andMap);
-
 productCategory = catResult.productCategory;
 productCategoryMembers = catResult.productCategoryMembers;
-
-// Prevents out of stock product to be displayed on site
-productStore = ProductStoreWorker.getProductStore(request);
-if(productStore) {
-    if("N".equals(productStore.showOutOfStockProducts)) {
-        productsInStock = [];
-        productCategoryMembers.each { productCategoryMember ->
-            product = delegator.findOne("Product", [productId : productCategoryMember.productId], true);
-            boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.productTypeId, "parentTypeId", "MARKETING_PKG");
-            context.isMarketingPackage = (isMarketingPackage? "true": "false");
-            if (isMarketingPackage) {
-                resultOutput = dispatcher.runSync("getMktgPackagesAvailable", [productId : productCategoryMember.productId]);
-                availableInventory = resultOutput.availableToPromiseTotal;
-                if(availableInventory > 0) { 
-                    productsInStock.add(productCategoryMember);
-                }
-            } else {
-                facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition([productId : productCategoryMember.productId]), null, null, null, false);
-                availableInventory = 0.0;
-                if (facilities) {
-                    facilities.each { facility ->
-                        lastInventoryCount = facility.lastInventoryCount;
-                        if (lastInventoryCount != null) {
-                            availableInventory += lastInventoryCount;
-                        }
-                    }
-                    if (availableInventory > 0) {
-                        productsInStock.add(productCategoryMember);
-                    }
-                }
-            }
-        }
-        context.productCategoryMembers = productsInStock;
-    } else {
-        context.productCategoryMembers = productCategoryMembers;
-    }
-}
+context.productCategoryMembers = productCategoryMembers;
 context.productCategory = productCategory;
 context.viewIndex = catResult.viewIndex;
 context.viewSize = catResult.viewSize;

Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl?rev=1632760&r1=1632759&r2=1632760&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl (original)
+++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl Sat Oct 18 11:23:45 2014
@@ -41,14 +41,14 @@ under the License.
 </script>
 
 <#macro paginationControls>
-    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize - 1)?double / viewSize?double)>
+    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize)?double / viewSize?double)>
       <#if (viewIndexMax?int > 0)>
         <div class="product-prevnext">
             <select name="pageSelect" onchange="callDocumentByPaginate(this[this.selectedIndex].value);">
                 <option value="#">${uiLabelMap.CommonPage} ${viewIndex?int + 1} ${uiLabelMap.CommonOf} ${viewIndexMax}</option>
                 <#if (viewIndex?int > 1)>
-                    <#list 0..viewIndexMax as curViewNum>
-                         <option value="${productCategoryId}~${viewSize}~${curViewNum?int}">${uiLabelMap.CommonGotoPage} ${curViewNum + 1}</option>
+                    <#list 1..viewIndexMax as curViewNum>
+                         <option value="${productCategoryId}~${viewSize}~${curViewNum-1?int}">${uiLabelMap.CommonGotoPage} ${curViewNum}</option>
                     </#list>
                 </#if>
             </select>

Modified: ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml?rev=1632760&r1=1632759&r2=1632760&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml (original)
+++ ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml Sat Oct 18 11:23:45 2014
@@ -152,6 +152,7 @@ under the License.
         <attribute name="introductionDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
         <attribute name="releaseDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
         <attribute name="orderByFields" type="List" mode="IN" optional="true"/>
+        <attribute name="productStoreId" mode="IN" type="String" optional="true"/>
         <attribute name="productCategory" type="org.ofbiz.entity.GenericValue" mode="OUT" optional="true"/>
         <attribute name="productCategoryMembers" type="java.util.Collection" mode="OUT" optional="true"/> <!-- this list will only contain the limited members if limitView=true -->
         <attribute name="viewIndex" type="Integer" mode="OUT" optional="false"/> <!-- this is a 1 based index, ie the first results are in index 1 -->

Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java?rev=1632760&r1=1632759&r2=1632760&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
+++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java Sat Oct 18 11:23:45 2014
@@ -21,7 +21,9 @@ package org.ofbiz.product.category;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.math.BigDecimal;
 import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -35,6 +37,7 @@ import javolution.util.FastMap;
 import net.sf.json.JSONObject;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
@@ -48,9 +51,13 @@ import org.ofbiz.entity.condition.Entity
 import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityTypeUtil;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.product.catalog.CatalogWorker;
+import org.ofbiz.product.product.ProductWorker;
 import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ServiceUtil;
 
 /**
@@ -212,6 +219,7 @@ public class CategoryServices {
 
     public static Map<String, Object> getProductCategoryAndLimitedMembers(DispatchContext dctx, Map<String, ? extends Object> context) {
         Delegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
         String productCategoryId = (String) context.get("productCategoryId");
         boolean limitView = ((Boolean) context.get("limitView")).booleanValue();
         int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue();
@@ -237,7 +245,7 @@ public class CategoryServices {
         }
 
         Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
-
+        
         int viewIndex = 0;
         try {
             viewIndex = Integer.valueOf((String) context.get("viewIndexString")).intValue();
@@ -272,7 +280,18 @@ public class CategoryServices {
             lowIndex = 0;
             highIndex = 0;
         }
-
+        Boolean filterOutOfStock = false ;
+        try {
+            String productStoreId = (String) context.get("productStoreId");
+            if (UtilValidate.isNotEmpty(productStoreId)) {
+                GenericValue productStore = delegator.findOne("ProductStore", UtilMisc.toMap("productStoreId", productStoreId), false);
+                if (productStore != null && "N".equals(productStore.getString("showOutOfStockProducts"))) {
+                    filterOutOfStock = true;
+                }
+            }
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e.getMessage(), module);
+        }
         List<GenericValue> productCategoryMembers = null;
         if (productCategory != null) {
             try {
@@ -293,7 +312,16 @@ public class CategoryServices {
                     if (!filterConditions.isEmpty()) {
                         productCategoryMembers = EntityUtil.filterByCondition(productCategoryMembers, EntityCondition.makeCondition(filterConditions, EntityOperator.AND));
                     }
-
+                    
+                    // filter out of stock products
+                    if (filterOutOfStock) {
+                        try {
+                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
+                        } catch (GeneralException e) {
+                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
+                        }
+                        
+                    }
                     // filter out the view allow before getting the sublist
                     if (UtilValidate.isNotEmpty(viewProductCategoryId)) {
                         productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
@@ -371,7 +399,15 @@ public class CategoryServices {
                         lowIndex = 1;
                         highIndex = listSize;
                     }
-
+                    // filter out of stock products
+                    if (filterOutOfStock) {
+                        try {
+                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
+                            listSize = productCategoryMembers.size();
+                        } catch (GeneralException e) {
+                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
+                        }
+                    }
                     // null safety
                     if (productCategoryMembers == null) {
                         productCategoryMembers = FastList.newInstance();
@@ -399,7 +435,7 @@ public class CategoryServices {
         if (productCategoryMembers != null) result.put("productCategoryMembers", productCategoryMembers);
         return result;
     }
-    
+
     // Please note : the structure of map in this function is according to the JSON data map of the jsTree
     @SuppressWarnings("unchecked")
     public static void getChildCategoryTree(HttpServletRequest request, HttpServletResponse response){

Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1632760&r1=1632759&r2=1632760&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original)
+++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java Sat Oct 18 11:23:45 2014
@@ -21,6 +21,7 @@ package org.ofbiz.product.product;
 import java.math.BigDecimal;
 import java.math.MathContext;
 import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
@@ -32,6 +33,7 @@ import javolution.util.FastMap;
 import javolution.util.FastSet;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
@@ -1205,4 +1207,43 @@ nextProd:
 
         return false;
     }
+
+    // Method to filter-out out of stock products 
+    public static List<GenericValue> filterOutOfStockProducts (List<GenericValue> productsToFilter, LocalDispatcher dispatcher, Delegator delegator) throws GeneralException {
+        ArrayList<GenericValue> productsInStock = new ArrayList<GenericValue>();
+        if (UtilValidate.isNotEmpty(productsToFilter)) {
+            for (GenericValue genericRecord : productsToFilter) {
+                String productId = genericRecord.getString("productId");
+                GenericValue product = null;
+                product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
+                Boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG");
+                
+                if ( UtilValidate.isNotEmpty(isMarketingPackage) && isMarketingPackage) {
+                    Map<String, Object> resultOutput = new FastMap<String, Object>();
+                    resultOutput = dispatcher.runSync("getMktgPackagesAvailable", UtilMisc.toMap("productId" ,productId));
+                    Debug.logWarning("Error getting available marketing package.", module);
+                    
+                    BigDecimal availableInventory = (BigDecimal) resultOutput.get("availableToPromiseTotal");
+                    if(availableInventory.compareTo(BigDecimal.ZERO) > 0) { 
+                        productsInStock.add(genericRecord);
+                    }
+                } else {
+                    List<GenericValue> facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition("productId",EntityOperator.EQUALS, productId), null, null, null, false);
+                    BigDecimal availableInventory = BigDecimal.ZERO;
+                    if (UtilValidate.isNotEmpty(facilities)) {
+                        for (GenericValue facility : facilities) {
+                            BigDecimal lastInventoryCount = facility.getBigDecimal("lastInventoryCount");
+                            if (lastInventoryCount != null) {
+                                availableInventory = lastInventoryCount.add(availableInventory);
+                            }
+                        }
+                        if (availableInventory.compareTo(BigDecimal.ZERO) > 0) {
+                            productsInStock.add(genericRecord);
+                        }
+                    }
+                }
+            }
+        }
+        return productsInStock;
+    }
 }



Re: svn commit: r1632760 - in /ofbiz/branches/release13.07/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ order/webapp/ordermgr/entry/catalog/ product/servicedef/ product/src/org/ofbiz/product/category/ product/src/org/ofbiz/product/pro...

Posted by Ashish Vijaywargiya <vi...@gmail.com>.
I have removed the unused import in commit revision 1635489. Thanks!

--
Kind Regards,
Ashish Vijaywargiya

On Fri, Oct 24, 2014 at 1:09 AM, Ashish Vijaywargiya <
ashish.vijaywargiya@hotwaxmedia.com> wrote:

> Hello Gil,
>
> I will get back to this conversation in next week. Thanks!
>
> --
> Ashish
>
> ----- gil portenseigne <gi...@nereide.fr> wrote:
> | I ashish,
> |
> | Is there a reason to introduce these imports in : CategoryServices.java,
> | these might be remains of devel
> |
> |   import java.io.Writer;
> | +import java.math.BigDecimal;
> |   import java.sql.Timestamp;
> | +import java.util.ArrayList;
> |   import java.util.List;
> |
> | [...]
> |
> |   import org.ofbiz.entity.util.EntityListIterator;
> | +import org.ofbiz.entity.util.EntityTypeUtil;
> |   import org.ofbiz.entity.util.EntityUtil;
> | [...]
> | +import org.ofbiz.service.GenericServiceException;
> |
> | My eclipse tell me they are no use here :).
> |
> | Not so important i guess, but to have less import is better.
> |
> | Other thing is formatting where you remove an empty line for spaces :
> |
> | @@ -237,7 +245,7 @@ public class CategoryServices {
> |           }
> |
> |           Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
> | -
> | +
> |           int viewIndex = 0;
> |           try {
> |
> |
> | Best Regards
> |
> | Gil
> |
> |
> | --
> |
> | <www.nereide.fr>
> |
> |       Gil Portenseigne
> | Consultant ERP OFBiz
> | Société Néréide
> | 3b Les isles
> | 37270 Veretz
> | Tel : 09 74 53 46 09, puis 1, poste 61
> | Mob : 06 82 740 444
> | www.nereide.fr <http://www.nereide.fr>
> |
> | Membre d'OFBiz France
> | www.ofbiz-fr.org <http://www.ofbiz-fr.org>
> |
>
>

Re: svn commit: r1632760 - in /ofbiz/branches/release13.07/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ order/webapp/ordermgr/entry/catalog/ product/servicedef/ product/src/org/ofbiz/product/category/ product/src/org/ofbiz/product/pro...

Posted by Ashish Vijaywargiya <as...@hotwaxmedia.com>.
Hello Gil, 

I will get back to this conversation in next week. Thanks!

--
Ashish

----- gil portenseigne <gi...@nereide.fr> wrote:
| I ashish,
| 
| Is there a reason to introduce these imports in : CategoryServices.java, 
| these might be remains of devel
| 
|   import java.io.Writer;
| +import java.math.BigDecimal;
|   import java.sql.Timestamp;
| +import java.util.ArrayList;
|   import java.util.List;
| 
| [...]
| 
|   import org.ofbiz.entity.util.EntityListIterator;
| +import org.ofbiz.entity.util.EntityTypeUtil;
|   import org.ofbiz.entity.util.EntityUtil;
| [...]
| +import org.ofbiz.service.GenericServiceException;
| 
| My eclipse tell me they are no use here :).
| 
| Not so important i guess, but to have less import is better.
| 
| Other thing is formatting where you remove an empty line for spaces :
| 
| @@ -237,7 +245,7 @@ public class CategoryServices {
|           }
|   
|           Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
| -
| +
|           int viewIndex = 0;
|           try {
| 
| 
| Best Regards
| 
| Gil
| 
| Le 18/10/2014 13:23, ashish@apache.org a écrit :
| > Author: ashish
| > Date: Sat Oct 18 11:23:45 2014
| > New Revision: 1632760
| >
| > URL: http://svn.apache.org/r1632760
| > Log:
| > Applied bug fix from trunk r1632750.
| > ===========================================
| > Applied patch from jira issue - OFBIZ-4528 - Out of stock products screw up the pagination during category browsing.
| > ===================================================================
| > Pagination is handled in getProductCategoryAndLimitedMembers
| > Then the out of stock filtering is done in CategoryDetail.groovy.
| > Hence the pagination is screwed up. Certain pages might show less records or no records based upon data condition.
| > ===================================================================
| > Thanks Arun for the contribution and Thanks Kiran for creating the issue.
| >
| > Modified:
| >      ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
| >      ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
| >      ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
| >      ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
| >      ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java
| >
| > Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
| > URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy?rev=1632760&r1=1632759&r2=1632760&view=diff
| > ==============================================================================
| > --- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy (original)
| > +++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy Sat Oct 18 11:23:45 2014
| > @@ -54,52 +54,20 @@ andMap = [productCategoryId : productCat
| >           limitView : limitView];
| >   andMap.put("prodCatalogId", currentCatalogId);
| >   andMap.put("checkViewAllow", true);
| > +// Prevents out of stock product to be displayed on site
| > +productStore = ProductStoreWorker.getProductStore(request);
| > +if (productStore) {
| > +    andMap.put("productStoreId", productStore.productStoreId);
| > +}
| >   if (context.orderByFields) {
| >       andMap.put("orderByFields", context.orderByFields);
| >   } else {
| >       andMap.put("orderByFields", ["sequenceNum", "productId"]);
| >   }
| >   catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers", andMap);
| > -
| >   productCategory = catResult.productCategory;
| >   productCategoryMembers = catResult.productCategoryMembers;
| > -
| > -// Prevents out of stock product to be displayed on site
| > -productStore = ProductStoreWorker.getProductStore(request);
| > -if(productStore) {
| > -    if("N".equals(productStore.showOutOfStockProducts)) {
| > -        productsInStock = [];
| > -        productCategoryMembers.each { productCategoryMember ->
| > -            product = delegator.findOne("Product", [productId : productCategoryMember.productId], true);
| > -            boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.productTypeId, "parentTypeId", "MARKETING_PKG");
| > -            context.isMarketingPackage = (isMarketingPackage? "true": "false");
| > -            if (isMarketingPackage) {
| > -                resultOutput = dispatcher.runSync("getMktgPackagesAvailable", [productId : productCategoryMember.productId]);
| > -                availableInventory = resultOutput.availableToPromiseTotal;
| > -                if(availableInventory > 0) {
| > -                    productsInStock.add(productCategoryMember);
| > -                }
| > -            } else {
| > -                facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition([productId : productCategoryMember.productId]), null, null, null, false);
| > -                availableInventory = 0.0;
| > -                if (facilities) {
| > -                    facilities.each { facility ->
| > -                        lastInventoryCount = facility.lastInventoryCount;
| > -                        if (lastInventoryCount != null) {
| > -                            availableInventory += lastInventoryCount;
| > -                        }
| > -                    }
| > -                    if (availableInventory > 0) {
| > -                        productsInStock.add(productCategoryMember);
| > -                    }
| > -                }
| > -            }
| > -        }
| > -        context.productCategoryMembers = productsInStock;
| > -    } else {
| > -        context.productCategoryMembers = productCategoryMembers;
| > -    }
| > -}
| > +context.productCategoryMembers = productCategoryMembers;
| >   context.productCategory = productCategory;
| >   context.viewIndex = catResult.viewIndex;
| >   context.viewSize = catResult.viewSize;
| >
| > Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
| > URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl?rev=1632760&r1=1632759&r2=1632760&view=diff
| > ==============================================================================
| > --- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl (original)
| > +++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl Sat Oct 18 11:23:45 2014
| > @@ -41,14 +41,14 @@ under the License.
| >   </script>
| >   
| >   <#macro paginationControls>
| > -    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize - 1)?double / viewSize?double)>
| > +    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize)?double / viewSize?double)>
| >         <#if (viewIndexMax?int > 0)>
| >           <div class="product-prevnext">
| >               <select name="pageSelect" onchange="callDocumentByPaginate(this[this.selectedIndex].value);">
| >                   <option value="#">${uiLabelMap.CommonPage} ${viewIndex?int + 1} ${uiLabelMap.CommonOf} ${viewIndexMax}</option>
| >                   <#if (viewIndex?int > 1)>
| > -                    <#list 0..viewIndexMax as curViewNum>
| > -                         <option value="${productCategoryId}~${viewSize}~${curViewNum?int}">${uiLabelMap.CommonGotoPage} ${curViewNum + 1}</option>
| > +                    <#list 1..viewIndexMax as curViewNum>
| > +                         <option value="${productCategoryId}~${viewSize}~${curViewNum-1?int}">${uiLabelMap.CommonGotoPage} ${curViewNum}</option>
| >                       </#list>
| >                   </#if>
| >               </select>
| >
| > Modified: ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
| > URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml?rev=1632760&r1=1632759&r2=1632760&view=diff
| > ==============================================================================
| > --- ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml (original)
| > +++ ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml Sat Oct 18 11:23:45 2014
| > @@ -152,6 +152,7 @@ under the License.
| >           <attribute name="introductionDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
| >           <attribute name="releaseDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
| >           <attribute name="orderByFields" type="List" mode="IN" optional="true"/>
| > +        <attribute name="productStoreId" mode="IN" type="String" optional="true"/>
| >           <attribute name="productCategory" type="org.ofbiz.entity.GenericValue" mode="OUT" optional="true"/>
| >           <attribute name="productCategoryMembers" type="java.util.Collection" mode="OUT" optional="true"/> <!-- this list will only contain the limited members if limitView=true -->
| >           <attribute name="viewIndex" type="Integer" mode="OUT" optional="false"/> <!-- this is a 1 based index, ie the first results are in index 1 -->
| >
| > Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
| > URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java?rev=1632760&r1=1632759&r2=1632760&view=diff
| > ==============================================================================
| > --- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
| > +++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java Sat Oct 18 11:23:45 2014
| > @@ -21,7 +21,9 @@ package org.ofbiz.product.category;
| >   import java.io.IOException;
| >   import java.io.UnsupportedEncodingException;
| >   import java.io.Writer;
| > +import java.math.BigDecimal;
| >   import java.sql.Timestamp;
| > +import java.util.ArrayList;
| >   import java.util.List;
| >   import java.util.Locale;
| >   import java.util.Map;
| > @@ -35,6 +37,7 @@ import javolution.util.FastMap;
| >   import net.sf.json.JSONObject;
| >   
| >   import org.ofbiz.base.util.Debug;
| > +import org.ofbiz.base.util.GeneralException;
| >   import org.ofbiz.base.util.UtilDateTime;
| >   import org.ofbiz.base.util.UtilGenerics;
| >   import org.ofbiz.base.util.UtilMisc;
| > @@ -48,9 +51,13 @@ import org.ofbiz.entity.condition.Entity
| >   import org.ofbiz.entity.model.ModelEntity;
| >   import org.ofbiz.entity.util.EntityFindOptions;
| >   import org.ofbiz.entity.util.EntityListIterator;
| > +import org.ofbiz.entity.util.EntityTypeUtil;
| >   import org.ofbiz.entity.util.EntityUtil;
| >   import org.ofbiz.product.catalog.CatalogWorker;
| > +import org.ofbiz.product.product.ProductWorker;
| >   import org.ofbiz.service.DispatchContext;
| > +import org.ofbiz.service.GenericServiceException;
| > +import org.ofbiz.service.LocalDispatcher;
| >   import org.ofbiz.service.ServiceUtil;
| >   
| >   /**
| > @@ -212,6 +219,7 @@ public class CategoryServices {
| >   
| >       public static Map<String, Object> getProductCategoryAndLimitedMembers(DispatchContext dctx, Map<String, ? extends Object> context) {
| >           Delegator delegator = dctx.getDelegator();
| > +        LocalDispatcher dispatcher = dctx.getDispatcher();
| >           String productCategoryId = (String) context.get("productCategoryId");
| >           boolean limitView = ((Boolean) context.get("limitView")).booleanValue();
| >           int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue();
| > @@ -237,7 +245,7 @@ public class CategoryServices {
| >           }
| >   
| >           Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
| > -
| > +
| >           int viewIndex = 0;
| >           try {
| >               viewIndex = Integer.valueOf((String) context.get("viewIndexString")).intValue();
| > @@ -272,7 +280,18 @@ public class CategoryServices {
| >               lowIndex = 0;
| >               highIndex = 0;
| >           }
| > -
| > +        Boolean filterOutOfStock = false ;
| > +        try {
| > +            String productStoreId = (String) context.get("productStoreId");
| > +            if (UtilValidate.isNotEmpty(productStoreId)) {
| > +                GenericValue productStore = delegator.findOne("ProductStore", UtilMisc.toMap("productStoreId", productStoreId), false);
| > +                if (productStore != null && "N".equals(productStore.getString("showOutOfStockProducts"))) {
| > +                    filterOutOfStock = true;
| > +                }
| > +            }
| > +        } catch (GenericEntityException e) {
| > +            Debug.logWarning(e.getMessage(), module);
| > +        }
| >           List<GenericValue> productCategoryMembers = null;
| >           if (productCategory != null) {
| >               try {
| > @@ -293,7 +312,16 @@ public class CategoryServices {
| >                       if (!filterConditions.isEmpty()) {
| >                           productCategoryMembers = EntityUtil.filterByCondition(productCategoryMembers, EntityCondition.makeCondition(filterConditions, EntityOperator.AND));
| >                       }
| > -
| > +
| > +                    // filter out of stock products
| > +                    if (filterOutOfStock) {
| > +                        try {
| > +                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
| > +                        } catch (GeneralException e) {
| > +                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
| > +                        }
| > +
| > +                    }
| >                       // filter out the view allow before getting the sublist
| >                       if (UtilValidate.isNotEmpty(viewProductCategoryId)) {
| >                           productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
| > @@ -371,7 +399,15 @@ public class CategoryServices {
| >                           lowIndex = 1;
| >                           highIndex = listSize;
| >                       }
| > -
| > +                    // filter out of stock products
| > +                    if (filterOutOfStock) {
| > +                        try {
| > +                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
| > +                            listSize = productCategoryMembers.size();
| > +                        } catch (GeneralException e) {
| > +                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
| > +                        }
| > +                    }
| >                       // null safety
| >                       if (productCategoryMembers == null) {
| >                           productCategoryMembers = FastList.newInstance();
| > @@ -399,7 +435,7 @@ public class CategoryServices {
| >           if (productCategoryMembers != null) result.put("productCategoryMembers", productCategoryMembers);
| >           return result;
| >       }
| > -
| > +
| >       // Please note : the structure of map in this function is according to the JSON data map of the jsTree
| >       @SuppressWarnings("unchecked")
| >       public static void getChildCategoryTree(HttpServletRequest request, HttpServletResponse response){
| >
| > Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java
| > URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1632760&r1=1632759&r2=1632760&view=diff
| > ==============================================================================
| > --- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original)
| > +++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java Sat Oct 18 11:23:45 2014
| > @@ -21,6 +21,7 @@ package org.ofbiz.product.product;
| >   import java.math.BigDecimal;
| >   import java.math.MathContext;
| >   import java.sql.Timestamp;
| > +import java.util.ArrayList;
| >   import java.util.LinkedHashMap;
| >   import java.util.List;
| >   import java.util.Locale;
| > @@ -32,6 +33,7 @@ import javolution.util.FastMap;
| >   import javolution.util.FastSet;
| >   
| >   import org.ofbiz.base.util.Debug;
| > +import org.ofbiz.base.util.GeneralException;
| >   import org.ofbiz.base.util.UtilDateTime;
| >   import org.ofbiz.base.util.UtilMisc;
| >   import org.ofbiz.base.util.UtilValidate;
| > @@ -1205,4 +1207,43 @@ nextProd:
| >   
| >           return false;
| >       }
| > +
| > +    // Method to filter-out out of stock products
| > +    public static List<GenericValue> filterOutOfStockProducts (List<GenericValue> productsToFilter, LocalDispatcher dispatcher, Delegator delegator) throws GeneralException {
| > +        ArrayList<GenericValue> productsInStock = new ArrayList<GenericValue>();
| > +        if (UtilValidate.isNotEmpty(productsToFilter)) {
| > +            for (GenericValue genericRecord : productsToFilter) {
| > +                String productId = genericRecord.getString("productId");
| > +                GenericValue product = null;
| > +                product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
| > +                Boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG");
| > +
| > +                if ( UtilValidate.isNotEmpty(isMarketingPackage) && isMarketingPackage) {
| > +                    Map<String, Object> resultOutput = new FastMap<String, Object>();
| > +                    resultOutput = dispatcher.runSync("getMktgPackagesAvailable", UtilMisc.toMap("productId" ,productId));
| > +                    Debug.logWarning("Error getting available marketing package.", module);
| > +
| > +                    BigDecimal availableInventory = (BigDecimal) resultOutput.get("availableToPromiseTotal");
| > +                    if(availableInventory.compareTo(BigDecimal.ZERO) > 0) {
| > +                        productsInStock.add(genericRecord);
| > +                    }
| > +                } else {
| > +                    List<GenericValue> facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition("productId",EntityOperator.EQUALS, productId), null, null, null, false);
| > +                    BigDecimal availableInventory = BigDecimal.ZERO;
| > +                    if (UtilValidate.isNotEmpty(facilities)) {
| > +                        for (GenericValue facility : facilities) {
| > +                            BigDecimal lastInventoryCount = facility.getBigDecimal("lastInventoryCount");
| > +                            if (lastInventoryCount != null) {
| > +                                availableInventory = lastInventoryCount.add(availableInventory);
| > +                            }
| > +                        }
| > +                        if (availableInventory.compareTo(BigDecimal.ZERO) > 0) {
| > +                            productsInStock.add(genericRecord);
| > +                        }
| > +                    }
| > +                }
| > +            }
| > +        }
| > +        return productsInStock;
| > +    }
| >   }
| >
| >
| 
| 
| -- 
| 
| <www.nereide.fr>
| 
| 	Gil Portenseigne
| Consultant ERP OFBiz
| Société Néréide
| 3b Les isles
| 37270 Veretz
| Tel : 09 74 53 46 09, puis 1, poste 61
| Mob : 06 82 740 444
| www.nereide.fr <http://www.nereide.fr>
| 
| Membre d'OFBiz France
| www.ofbiz-fr.org <http://www.ofbiz-fr.org>
| 


Re: svn commit: r1632760 - in /ofbiz/branches/release13.07/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ order/webapp/ordermgr/entry/catalog/ product/servicedef/ product/src/org/ofbiz/product/category/ product/src/org/ofbiz/product/pro...

Posted by gil portenseigne <gi...@nereide.fr>.
I ashish,

Is there a reason to introduce these imports in : CategoryServices.java, 
these might be remains of devel

  import java.io.Writer;
+import java.math.BigDecimal;
  import java.sql.Timestamp;
+import java.util.ArrayList;
  import java.util.List;

[...]

  import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityTypeUtil;
  import org.ofbiz.entity.util.EntityUtil;
[...]
+import org.ofbiz.service.GenericServiceException;

My eclipse tell me they are no use here :).

Not so important i guess, but to have less import is better.

Other thing is formatting where you remove an empty line for spaces :

@@ -237,7 +245,7 @@ public class CategoryServices {
          }
  
          Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
-
+
          int viewIndex = 0;
          try {


Best Regards

Gil

Le 18/10/2014 13:23, ashish@apache.org a écrit :
> Author: ashish
> Date: Sat Oct 18 11:23:45 2014
> New Revision: 1632760
>
> URL: http://svn.apache.org/r1632760
> Log:
> Applied bug fix from trunk r1632750.
> ===========================================
> Applied patch from jira issue - OFBIZ-4528 - Out of stock products screw up the pagination during category browsing.
> ===================================================================
> Pagination is handled in getProductCategoryAndLimitedMembers
> Then the out of stock filtering is done in CategoryDetail.groovy.
> Hence the pagination is screwed up. Certain pages might show less records or no records based upon data condition.
> ===================================================================
> Thanks Arun for the contribution and Thanks Kiran for creating the issue.
>
> Modified:
>      ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
>      ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
>      ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
>      ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
>      ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java
>
> Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy?rev=1632760&r1=1632759&r2=1632760&view=diff
> ==============================================================================
> --- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy (original)
> +++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy Sat Oct 18 11:23:45 2014
> @@ -54,52 +54,20 @@ andMap = [productCategoryId : productCat
>           limitView : limitView];
>   andMap.put("prodCatalogId", currentCatalogId);
>   andMap.put("checkViewAllow", true);
> +// Prevents out of stock product to be displayed on site
> +productStore = ProductStoreWorker.getProductStore(request);
> +if (productStore) {
> +    andMap.put("productStoreId", productStore.productStoreId);
> +}
>   if (context.orderByFields) {
>       andMap.put("orderByFields", context.orderByFields);
>   } else {
>       andMap.put("orderByFields", ["sequenceNum", "productId"]);
>   }
>   catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers", andMap);
> -
>   productCategory = catResult.productCategory;
>   productCategoryMembers = catResult.productCategoryMembers;
> -
> -// Prevents out of stock product to be displayed on site
> -productStore = ProductStoreWorker.getProductStore(request);
> -if(productStore) {
> -    if("N".equals(productStore.showOutOfStockProducts)) {
> -        productsInStock = [];
> -        productCategoryMembers.each { productCategoryMember ->
> -            product = delegator.findOne("Product", [productId : productCategoryMember.productId], true);
> -            boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.productTypeId, "parentTypeId", "MARKETING_PKG");
> -            context.isMarketingPackage = (isMarketingPackage? "true": "false");
> -            if (isMarketingPackage) {
> -                resultOutput = dispatcher.runSync("getMktgPackagesAvailable", [productId : productCategoryMember.productId]);
> -                availableInventory = resultOutput.availableToPromiseTotal;
> -                if(availableInventory > 0) {
> -                    productsInStock.add(productCategoryMember);
> -                }
> -            } else {
> -                facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition([productId : productCategoryMember.productId]), null, null, null, false);
> -                availableInventory = 0.0;
> -                if (facilities) {
> -                    facilities.each { facility ->
> -                        lastInventoryCount = facility.lastInventoryCount;
> -                        if (lastInventoryCount != null) {
> -                            availableInventory += lastInventoryCount;
> -                        }
> -                    }
> -                    if (availableInventory > 0) {
> -                        productsInStock.add(productCategoryMember);
> -                    }
> -                }
> -            }
> -        }
> -        context.productCategoryMembers = productsInStock;
> -    } else {
> -        context.productCategoryMembers = productCategoryMembers;
> -    }
> -}
> +context.productCategoryMembers = productCategoryMembers;
>   context.productCategory = productCategory;
>   context.viewIndex = catResult.viewIndex;
>   context.viewSize = catResult.viewSize;
>
> Modified: ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl?rev=1632760&r1=1632759&r2=1632760&view=diff
> ==============================================================================
> --- ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl (original)
> +++ ofbiz/branches/release13.07/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl Sat Oct 18 11:23:45 2014
> @@ -41,14 +41,14 @@ under the License.
>   </script>
>   
>   <#macro paginationControls>
> -    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize - 1)?double / viewSize?double)>
> +    <#assign viewIndexMax = Static["java.lang.Math"].ceil((listSize)?double / viewSize?double)>
>         <#if (viewIndexMax?int > 0)>
>           <div class="product-prevnext">
>               <select name="pageSelect" onchange="callDocumentByPaginate(this[this.selectedIndex].value);">
>                   <option value="#">${uiLabelMap.CommonPage} ${viewIndex?int + 1} ${uiLabelMap.CommonOf} ${viewIndexMax}</option>
>                   <#if (viewIndex?int > 1)>
> -                    <#list 0..viewIndexMax as curViewNum>
> -                         <option value="${productCategoryId}~${viewSize}~${curViewNum?int}">${uiLabelMap.CommonGotoPage} ${curViewNum + 1}</option>
> +                    <#list 1..viewIndexMax as curViewNum>
> +                         <option value="${productCategoryId}~${viewSize}~${curViewNum-1?int}">${uiLabelMap.CommonGotoPage} ${curViewNum}</option>
>                       </#list>
>                   </#if>
>               </select>
>
> Modified: ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml?rev=1632760&r1=1632759&r2=1632760&view=diff
> ==============================================================================
> --- ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml (original)
> +++ ofbiz/branches/release13.07/applications/product/servicedef/services_view.xml Sat Oct 18 11:23:45 2014
> @@ -152,6 +152,7 @@ under the License.
>           <attribute name="introductionDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
>           <attribute name="releaseDateLimit" type="java.sql.Timestamp" mode="IN" optional="true"/>
>           <attribute name="orderByFields" type="List" mode="IN" optional="true"/>
> +        <attribute name="productStoreId" mode="IN" type="String" optional="true"/>
>           <attribute name="productCategory" type="org.ofbiz.entity.GenericValue" mode="OUT" optional="true"/>
>           <attribute name="productCategoryMembers" type="java.util.Collection" mode="OUT" optional="true"/> <!-- this list will only contain the limited members if limitView=true -->
>           <attribute name="viewIndex" type="Integer" mode="OUT" optional="false"/> <!-- this is a 1 based index, ie the first results are in index 1 -->
>
> Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java?rev=1632760&r1=1632759&r2=1632760&view=diff
> ==============================================================================
> --- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
> +++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/category/CategoryServices.java Sat Oct 18 11:23:45 2014
> @@ -21,7 +21,9 @@ package org.ofbiz.product.category;
>   import java.io.IOException;
>   import java.io.UnsupportedEncodingException;
>   import java.io.Writer;
> +import java.math.BigDecimal;
>   import java.sql.Timestamp;
> +import java.util.ArrayList;
>   import java.util.List;
>   import java.util.Locale;
>   import java.util.Map;
> @@ -35,6 +37,7 @@ import javolution.util.FastMap;
>   import net.sf.json.JSONObject;
>   
>   import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.GeneralException;
>   import org.ofbiz.base.util.UtilDateTime;
>   import org.ofbiz.base.util.UtilGenerics;
>   import org.ofbiz.base.util.UtilMisc;
> @@ -48,9 +51,13 @@ import org.ofbiz.entity.condition.Entity
>   import org.ofbiz.entity.model.ModelEntity;
>   import org.ofbiz.entity.util.EntityFindOptions;
>   import org.ofbiz.entity.util.EntityListIterator;
> +import org.ofbiz.entity.util.EntityTypeUtil;
>   import org.ofbiz.entity.util.EntityUtil;
>   import org.ofbiz.product.catalog.CatalogWorker;
> +import org.ofbiz.product.product.ProductWorker;
>   import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.GenericServiceException;
> +import org.ofbiz.service.LocalDispatcher;
>   import org.ofbiz.service.ServiceUtil;
>   
>   /**
> @@ -212,6 +219,7 @@ public class CategoryServices {
>   
>       public static Map<String, Object> getProductCategoryAndLimitedMembers(DispatchContext dctx, Map<String, ? extends Object> context) {
>           Delegator delegator = dctx.getDelegator();
> +        LocalDispatcher dispatcher = dctx.getDispatcher();
>           String productCategoryId = (String) context.get("productCategoryId");
>           boolean limitView = ((Boolean) context.get("limitView")).booleanValue();
>           int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue();
> @@ -237,7 +245,7 @@ public class CategoryServices {
>           }
>   
>           Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
> -
> +
>           int viewIndex = 0;
>           try {
>               viewIndex = Integer.valueOf((String) context.get("viewIndexString")).intValue();
> @@ -272,7 +280,18 @@ public class CategoryServices {
>               lowIndex = 0;
>               highIndex = 0;
>           }
> -
> +        Boolean filterOutOfStock = false ;
> +        try {
> +            String productStoreId = (String) context.get("productStoreId");
> +            if (UtilValidate.isNotEmpty(productStoreId)) {
> +                GenericValue productStore = delegator.findOne("ProductStore", UtilMisc.toMap("productStoreId", productStoreId), false);
> +                if (productStore != null && "N".equals(productStore.getString("showOutOfStockProducts"))) {
> +                    filterOutOfStock = true;
> +                }
> +            }
> +        } catch (GenericEntityException e) {
> +            Debug.logWarning(e.getMessage(), module);
> +        }
>           List<GenericValue> productCategoryMembers = null;
>           if (productCategory != null) {
>               try {
> @@ -293,7 +312,16 @@ public class CategoryServices {
>                       if (!filterConditions.isEmpty()) {
>                           productCategoryMembers = EntityUtil.filterByCondition(productCategoryMembers, EntityCondition.makeCondition(filterConditions, EntityOperator.AND));
>                       }
> -
> +
> +                    // filter out of stock products
> +                    if (filterOutOfStock) {
> +                        try {
> +                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
> +                        } catch (GeneralException e) {
> +                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
> +                        }
> +
> +                    }
>                       // filter out the view allow before getting the sublist
>                       if (UtilValidate.isNotEmpty(viewProductCategoryId)) {
>                           productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
> @@ -371,7 +399,15 @@ public class CategoryServices {
>                           lowIndex = 1;
>                           highIndex = listSize;
>                       }
> -
> +                    // filter out of stock products
> +                    if (filterOutOfStock) {
> +                        try {
> +                            productCategoryMembers = ProductWorker.filterOutOfStockProducts(productCategoryMembers, dispatcher, delegator);
> +                            listSize = productCategoryMembers.size();
> +                        } catch (GeneralException e) {
> +                            Debug.logWarning("Problem filtering out of stock products :"+e.getMessage(), module);
> +                        }
> +                    }
>                       // null safety
>                       if (productCategoryMembers == null) {
>                           productCategoryMembers = FastList.newInstance();
> @@ -399,7 +435,7 @@ public class CategoryServices {
>           if (productCategoryMembers != null) result.put("productCategoryMembers", productCategoryMembers);
>           return result;
>       }
> -
> +
>       // Please note : the structure of map in this function is according to the JSON data map of the jsTree
>       @SuppressWarnings("unchecked")
>       public static void getChildCategoryTree(HttpServletRequest request, HttpServletResponse response){
>
> Modified: ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1632760&r1=1632759&r2=1632760&view=diff
> ==============================================================================
> --- ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original)
> +++ ofbiz/branches/release13.07/applications/product/src/org/ofbiz/product/product/ProductWorker.java Sat Oct 18 11:23:45 2014
> @@ -21,6 +21,7 @@ package org.ofbiz.product.product;
>   import java.math.BigDecimal;
>   import java.math.MathContext;
>   import java.sql.Timestamp;
> +import java.util.ArrayList;
>   import java.util.LinkedHashMap;
>   import java.util.List;
>   import java.util.Locale;
> @@ -32,6 +33,7 @@ import javolution.util.FastMap;
>   import javolution.util.FastSet;
>   
>   import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.GeneralException;
>   import org.ofbiz.base.util.UtilDateTime;
>   import org.ofbiz.base.util.UtilMisc;
>   import org.ofbiz.base.util.UtilValidate;
> @@ -1205,4 +1207,43 @@ nextProd:
>   
>           return false;
>       }
> +
> +    // Method to filter-out out of stock products
> +    public static List<GenericValue> filterOutOfStockProducts (List<GenericValue> productsToFilter, LocalDispatcher dispatcher, Delegator delegator) throws GeneralException {
> +        ArrayList<GenericValue> productsInStock = new ArrayList<GenericValue>();
> +        if (UtilValidate.isNotEmpty(productsToFilter)) {
> +            for (GenericValue genericRecord : productsToFilter) {
> +                String productId = genericRecord.getString("productId");
> +                GenericValue product = null;
> +                product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);
> +                Boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG");
> +
> +                if ( UtilValidate.isNotEmpty(isMarketingPackage) && isMarketingPackage) {
> +                    Map<String, Object> resultOutput = new FastMap<String, Object>();
> +                    resultOutput = dispatcher.runSync("getMktgPackagesAvailable", UtilMisc.toMap("productId" ,productId));
> +                    Debug.logWarning("Error getting available marketing package.", module);
> +
> +                    BigDecimal availableInventory = (BigDecimal) resultOutput.get("availableToPromiseTotal");
> +                    if(availableInventory.compareTo(BigDecimal.ZERO) > 0) {
> +                        productsInStock.add(genericRecord);
> +                    }
> +                } else {
> +                    List<GenericValue> facilities = delegator.findList("ProductFacility", EntityCondition.makeCondition("productId",EntityOperator.EQUALS, productId), null, null, null, false);
> +                    BigDecimal availableInventory = BigDecimal.ZERO;
> +                    if (UtilValidate.isNotEmpty(facilities)) {
> +                        for (GenericValue facility : facilities) {
> +                            BigDecimal lastInventoryCount = facility.getBigDecimal("lastInventoryCount");
> +                            if (lastInventoryCount != null) {
> +                                availableInventory = lastInventoryCount.add(availableInventory);
> +                            }
> +                        }
> +                        if (availableInventory.compareTo(BigDecimal.ZERO) > 0) {
> +                            productsInStock.add(genericRecord);
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +        return productsInStock;
> +    }
>   }
>
>


-- 

<www.nereide.fr>

	Gil Portenseigne
Consultant ERP OFBiz
Société Néréide
3b Les isles
37270 Veretz
Tel : 09 74 53 46 09, puis 1, poste 61
Mob : 06 82 740 444
www.nereide.fr <http://www.nereide.fr>

Membre d'OFBiz France
www.ofbiz-fr.org <http://www.ofbiz-fr.org>