⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productdisplayworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: ProductDisplayWorker.java 5462 2005-08-05 18:35:48Z jonesde $ * *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.order.shoppingcart.product;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.servlet.ServletRequest;import javax.servlet.http.HttpServletRequest;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntity;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.order.shoppingcart.ShoppingCart;import org.ofbiz.order.shoppingcart.ShoppingCartItem;import org.ofbiz.product.catalog.CatalogWorker;import org.ofbiz.product.category.CategoryWorker;/** * @author ajzeneski */public class ProductDisplayWorker {        public static final String module = ProductDisplayWorker.class.getName();    /* ========================================================================================*/        /* ============================= Special Data Retreival Methods ===========================*/            public static List getRandomCartProductAssoc(ServletRequest request, boolean checkViewAllow) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        HttpServletRequest httpRequest = (HttpServletRequest) request;        ShoppingCart cart = (ShoppingCart) httpRequest.getSession().getAttribute("shoppingCart");        if (cart == null || cart.size() <= 0) return null;        ArrayList cartAssocs = null;        try {            Map products = new HashMap();            Iterator cartiter = cart.iterator();            while (cartiter != null && cartiter.hasNext()) {                ShoppingCartItem item = (ShoppingCartItem) cartiter.next();                // Collection upgradeProducts = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", item.getProductId(), "productAssocTypeId", "PRODUCT_UPGRADE"), null);                List complementProducts = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", item.getProductId(), "productAssocTypeId", "PRODUCT_COMPLEMENT"), null);                // since ProductAssoc records have a fromDate and thruDate, we can filter by now so that only assocs in the date range are included                complementProducts = EntityUtil.filterByDate(complementProducts, true);                                List productsCategories = delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productId", item.getProductId()), null);                productsCategories = EntityUtil.filterByDate(productsCategories, true);                if (productsCategories != null) {                    Iterator productsCategoriesIter = productsCategories.iterator();                    while (productsCategoriesIter.hasNext()) {                        GenericValue productsCategoryMember = (GenericValue) productsCategoriesIter.next();                        GenericValue productsCategory = productsCategoryMember.getRelatedOneCache("ProductCategory");                        if ("CROSS_SELL_CATEGORY".equals(productsCategory.getString("productCategoryTypeId"))) {                            List curPcms = productsCategory.getRelatedCache("ProductCategoryMember");                            if (curPcms != null) {                                Iterator curPcmsIter = curPcms.iterator();                                while (curPcmsIter.hasNext()) {                                    GenericValue curPcm = (GenericValue) curPcmsIter.next();                                    if (!products.containsKey(curPcm.getString("productId"))) {                                        GenericValue product = curPcm.getRelatedOneCache("Product");                                        products.put(product.getString("productId"), product);                                    }                                }                            }                        }                    }                }                if (complementProducts != null && complementProducts.size() > 0) {                    Iterator complIter = complementProducts.iterator();                    while (complIter.hasNext()) {                        GenericValue productAssoc = (GenericValue) complIter.next();                        if (!products.containsKey(productAssoc.getString("productIdTo"))) {                            GenericValue product = productAssoc.getRelatedOneCache("AssocProduct");                            products.put(product.getString("productId"), product);                        }                    }                }            }            // remove all products that are already in the cart            cartiter = cart.iterator();            while (cartiter != null && cartiter.hasNext()) {                ShoppingCartItem item = (ShoppingCartItem) cartiter.next();                products.remove(item.getProductId());            }            // if desired check view allow category            if (checkViewAllow) {                String currentCatalogId = CatalogWorker.getCurrentCatalogId(request);                String viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, currentCatalogId);                if (viewProductCategoryId != null) {                    List tempList = new ArrayList(products.values());                    tempList = CategoryWorker.filterProductsInCategory(delegator, tempList, viewProductCategoryId, "productId");                    cartAssocs = new ArrayList(tempList);                }            }                        if (cartAssocs == null) {                cartAssocs = new ArrayList(products.values());            }            // randomly remove products while there are more than 3            while (cartAssocs.size() > 3) {                int toRemove = (int) (Math.random() * (double) (cartAssocs.size()));                cartAssocs.remove(toRemove);            }        } catch (GenericEntityException e) {            Debug.logWarning(e, module);        }                if (cartAssocs != null && cartAssocs.size() > 0) {            return cartAssocs;        } else {            return null;        }    }                    public static Map getQuickReorderProducts(ServletRequest request) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        HttpServletRequest httpRequest = (HttpServletRequest) request;        GenericValue userLogin = (GenericValue) httpRequest.getSession().getAttribute("userLogin");        Map results = new HashMap();        if (userLogin == null) userLogin = (GenericValue) httpRequest.getSession().getAttribute("autoUserLogin");        if (userLogin == null) return results;        try {            Map products = (Map) httpRequest.getSession().getAttribute("_QUICK_REORDER_PRODUCTS_");            Map productQuantities = (Map) httpRequest.getSession().getAttribute("_QUICK_REORDER_PRODUCT_QUANTITIES_");            Map productOccurances = (Map) httpRequest.getSession().getAttribute("_QUICK_REORDER_PRODUCT_OCCURANCES_");            if (products == null || productQuantities == null || productOccurances == null) {                products = new HashMap();                productQuantities = new HashMap();                // keep track of how many times a product occurs in order to find averages and rank by purchase amount                productOccurances = new HashMap();                // get all order role entities for user by customer role type                // final String[] USER_ORDER_ROLE_TYPES = {"END_USER_CUSTOMER", "SHIP_TO_CUSTOMER", "BILL_TO_CUSTOMER", "PLACING_CUSTOMER"};                final String[] USER_ORDER_ROLE_TYPES = {"PLACING_CUSTOMER"};                for (int i = 0; i < USER_ORDER_ROLE_TYPES.length; i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -