當前位置: 首頁>>代碼示例>>Java>>正文


Java CategoryWorker類代碼示例

本文整理匯總了Java中org.ofbiz.product.category.CategoryWorker的典型用法代碼示例。如果您正苦於以下問題:Java CategoryWorker類的具體用法?Java CategoryWorker怎麽用?Java CategoryWorker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CategoryWorker類屬於org.ofbiz.product.category包,在下文中一共展示了CategoryWorker類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getProductRollupTrails

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/**
 * SCIPIO: Returns all rollups for a product that have the given top categories.
 * TODO: REVIEW: maybe this can be optimized with a smarter algorithm?
 * Added 2017-11-09.
 */
public static List<List<String>> getProductRollupTrails(Delegator delegator, String productId, Set<String> topCategoryIds, boolean useCache) {
    List<GenericValue> prodCatMembers;
    try {
        prodCatMembers = EntityQuery.use(delegator).from("ProductCategoryMember")
                .where("productId", productId).orderBy("-fromDate").filterByDate().cache(useCache).queryList();
    } catch (GenericEntityException e) {
        Debug.logError("Cannot generate trail from product '" + productId + "'", productId);
        return new ArrayList<>();
    }
    if (prodCatMembers.size() == 0) return new ArrayList<>();
    
    List<List<String>> possibleTrails = null;
    for(GenericValue prodCatMember : prodCatMembers) {
        List<List<String>> trails = CategoryWorker.getCategoryRollupTrails(delegator, prodCatMember.getString("productCategoryId"), topCategoryIds, useCache);
        if (possibleTrails == null) possibleTrails = trails;
        else possibleTrails.addAll(trails);
    }
    return possibleTrails;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:25,代碼來源:ProductWorker.java

示例2: getCurrentCatalogId

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/**
 * Retrieves the current prodCatalogId.  First it will attempt to find it from a special
 * request parameter or session attribute named CURRENT_CATALOG_ID.  Failing that, it will
 * get the first catalog from the database as specified in getCatalogIdsAvailable().
 * If this behavior is undesired, give the user a selectable list of catalogs.
 * <p>
 * SCIPIO: 2017-08-15: now supports reading CURRENT_CATALOG_ID without storing back to session (save boolean).
 */
public static String getCurrentCatalogId(ServletRequest request, boolean save, boolean saveTrail) {
    HttpSession session = ((HttpServletRequest) request).getSession();
    Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request);
    String prodCatalogId = null;
    boolean fromSession = false;

    // first see if a new catalog was specified as a parameter
    prodCatalogId = (String) requestParameters.get("CURRENT_CATALOG_ID");
    // if no parameter, try from session
    if (prodCatalogId == null) {
        prodCatalogId = (String) session.getAttribute("CURRENT_CATALOG_ID");
        if (prodCatalogId != null) fromSession = true;
    }
    // get it from the database
    if (prodCatalogId == null) {
        List<String> catalogIds = getCatalogIdsAvailable(request);
        if (UtilValidate.isNotEmpty(catalogIds)) prodCatalogId = catalogIds.get(0);
    }

    if (save && !fromSession) {
        if (Debug.verboseOn()) Debug.logVerbose("[CatalogWorker.getCurrentCatalogId] Setting new catalog name: " + prodCatalogId, module);
        session.setAttribute("CURRENT_CATALOG_ID", prodCatalogId);
        if (saveTrail) {
            // SCIPIO: 2016-13-22: Do NOT override the trail if it was already set earlier in request, 
            // otherwise may lose work done by servlets and filters
            //CategoryWorker.setTrail(request, FastList.<String>newInstance());
            CategoryWorker.setTrailIfFirstInRequest(request, FastList.<String>newInstance());
        }
    }
    return prodCatalogId;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:40,代碼來源:CatalogWorker.java

示例3: updateRequestForSeoCatalogUrl

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/**
     * Sets the product/category IDs in request and updates trail.
     */
    public static boolean updateRequestForSeoCatalogUrl(HttpServletRequest request, Delegator delegator, SeoCatalogUrlInfo urlInfo) {

        if (urlInfo.isProductRequest()) {
            if (urlInfo.getProductId() != null) {
                request.setAttribute("product_id", urlInfo.getProductId());
                request.setAttribute("productId", urlInfo.getProductId());
            }
            request.setAttribute("productCategoryId", urlInfo.getCategoryId()); // EVEN IF NULL!
        } else { // if (CatalogUrlServlet.CATEGORY_REQUEST.equals(targetRequest)) {
            request.setAttribute("productCategoryId", urlInfo.getCategoryId()); // EVEN IF NULL!
        }
        
        String rootCategoryId = null;
        if (urlInfo.getPathCategoryIds() != null && urlInfo.getPathCategoryIds().size() >= 1) {
            rootCategoryId = urlInfo.getPathCategoryIds().get(0);
        }
        request.setAttribute("rootCategoryId", rootCategoryId); // EVEN IF NULL!

        // FIXME: Doing something completely different until further review...
//        String topCategoryId = CatalogUrlFilter.getCatalogTopCategory(request);
//        List<GenericValue> trailCategories = CategoryWorker.getRelatedCategoriesRet(request, "trailCategories", topCategoryId, false, false, true);
//        List<String> trailCategoryIds = EntityUtil.getFieldListFromEntityList(trailCategories, "productCategoryId", true);
//        updateRequestTrail(request, delegator, urlInfo.getProductId(), urlInfo.getCategoryId(), trailCategoryIds, topCategoryId);
        
        // FOR NOW, just replace the whole trail with what we got for time being
        List<String> newTrail = FastList.newInstance(); // FastList legacy code
        newTrail.add("TOP");
        newTrail.addAll(urlInfo.getPathCategoryIds());
        if (urlInfo.getCategoryId() != null && !urlInfo.getCategoryId().equals(newTrail.get(newTrail.size() - 1))) {
            newTrail.add(urlInfo.getCategoryId());
        }
        CategoryWorker.setTrail(request, newTrail);
        
        request.setAttribute("categoryTrailUpdated", Boolean.TRUE); // SCIPIO: This is new
        
        return true;
    }
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:41,代碼來源:SeoCatalogUrlFilter.java

示例4: makeCategoryUrl

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
public String makeCategoryUrl(HttpServletRequest request, Locale locale, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    List<String> trail = CategoryWorker.getTrail(request);
    return makeCategoryUrl(delegator, dispatcher, locale, trail, 
            WebSiteWorker.getWebSiteId(request), request.getContextPath(), CatalogWorker.getCurrentCatalogId(request),
            previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:9,代碼來源:SeoCatalogUrlWorker.java

示例5: makeProductUrl

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
public String makeProductUrl(HttpServletRequest request, Locale locale, String previousCategoryId, String productCategoryId, String productId) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    List<String> trail = CategoryWorker.getTrail(request);
    
    return makeProductUrl(delegator, dispatcher, locale, trail, 
            WebSiteWorker.getWebSiteId(request), request.getContextPath(), CatalogWorker.getCurrentCatalogId(request),
            previousCategoryId, productCategoryId, productId);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:10,代碼來源:SeoCatalogUrlWorker.java

示例6: findProduct

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
public static GenericValue findProduct(Delegator delegator, boolean skipProductChecks, String prodCatalogId, String productId, Locale locale) throws CartItemModifyException, ItemNotFoundException {
    GenericValue product;

    try {
        product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache().queryOne();

        // first see if there is a purchase allow category and if this product is in it or not
        String purchaseProductCategoryId = CatalogWorker.getCatalogPurchaseAllowCategoryId(delegator, prodCatalogId);
        if (!skipProductChecks && product != null && purchaseProductCategoryId != null) {
            if (!CategoryWorker.isProductInCategory(delegator, product.getString("productId"), purchaseProductCategoryId)) {
                // a Purchase allow productCategoryId was found, but the product is not in the category, axe it...
                Debug.logWarning("Product [" + productId + "] is not in the purchase allow category [" + purchaseProductCategoryId + "] and cannot be purchased", module);
                product = null;
            }
        }
    } catch (GenericEntityException e) {
        Debug.logWarning(e.toString(), module);
        product = null;
    }

    if (product == null) {
        Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productId", productId);
        String excMsg = UtilProperties.getMessage(resource_error, "item.product_not_found", messageMap , locale);

        Debug.logWarning(excMsg, module);
        throw new ItemNotFoundException(excMsg);
    }
    return product;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:30,代碼來源:ShoppingCartItem.java

示例7: findAllCartItemsInCategory

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/** Get all ShoppingCartItems from the cart object with the given productCategoryId and optional groupNumber to limit it to a specific item group */
public List<ShoppingCartItem> findAllCartItemsInCategory(String productCategoryId, String groupNumber) {
    if (productCategoryId == null) return this.items();

    Delegator delegator = this.getDelegator();
    List<ShoppingCartItem> itemsToReturn = FastList.newInstance();
    try {
        // Check for existing cart item
        for (ShoppingCartItem cartItem : cartLines) {
            //Debug.logInfo("Checking cartItem with product [" + cartItem.getProductId() + "] becuase that is in group [" + (cartItem.getItemGroup()==null ? "no group" : cartItem.getItemGroup().getGroupNumber()) + "]", module);

            if (UtilValidate.isNotEmpty(groupNumber) && !cartItem.isInItemGroup(groupNumber)) {
                //Debug.logInfo("Not using cartItem with product [" + cartItem.getProductId() + "] becuase not in group [" + groupNumber + "]", module);
                continue;
            }
            if (CategoryWorker.isProductInCategory(delegator, cartItem.getProductId(), productCategoryId)) {
                itemsToReturn.add(cartItem);
            } else {
                //Debug.logInfo("Not using cartItem with product [" + cartItem.getProductId() + "] becuase not in category [" + productCategoryId + "]", module);
            }
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, "Error getting cart items that are in a category: " + e.toString(), module);
    }
    //Debug.logInfo("Got [" + itemsToReturn.size() + "] cart items in category [" + productCategoryId + "] and item group [" + groupNumber + "]", module);
    return itemsToReturn;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:28,代碼來源:ShoppingCart.java

示例8: getCurrentCatalogId

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/**
 * Retrieves the current prodCatalogId.  First it will attempt to find it from a special
 * request parameter or session attribute named CURRENT_CATALOG_ID.  Failing that, it will
 * get the first catalog from the database as specified in getCatalogIdsAvailable().
 * If this behavior is undesired, give the user a selectable list of catalogs.
 */
public static String getCurrentCatalogId(ServletRequest request) {
    HttpSession session = ((HttpServletRequest) request).getSession();
    Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request);
    String prodCatalogId = null;
    boolean fromSession = false;

    // first see if a new catalog was specified as a parameter
    prodCatalogId = (String) requestParameters.get("CURRENT_CATALOG_ID");
    // if no parameter, try from session
    if (prodCatalogId == null) {
        prodCatalogId = (String) session.getAttribute("CURRENT_CATALOG_ID");
        if (prodCatalogId != null) fromSession = true;
    }
    // get it from the database
    if (prodCatalogId == null) {
        List<String> catalogIds = getCatalogIdsAvailable(request);
        if (UtilValidate.isNotEmpty(catalogIds)) prodCatalogId = catalogIds.get(0);
    }

    if (!fromSession) {
        if (Debug.verboseOn()) Debug.logVerbose("[CatalogWorker.getCurrentCatalogId] Setting new catalog name: " + prodCatalogId, module);
        session.setAttribute("CURRENT_CATALOG_ID", prodCatalogId);
        CategoryWorker.setTrail(request, FastList.<String>newInstance());
    }
    return prodCatalogId;
}
 
開發者ID:gildaslemoal,項目名稱:elpi,代碼行數:33,代碼來源:CatalogWorker.java

示例9: findProduct

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
public static GenericValue findProduct(Delegator delegator, boolean skipProductChecks, String prodCatalogId, String productId, Locale locale) throws CartItemModifyException, ItemNotFoundException {
    GenericValue product;

    try {
        product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true);

        // first see if there is a purchase allow category and if this product is in it or not
        String purchaseProductCategoryId = CatalogWorker.getCatalogPurchaseAllowCategoryId(delegator, prodCatalogId);
        if (!skipProductChecks && product != null && purchaseProductCategoryId != null) {
            if (!CategoryWorker.isProductInCategory(delegator, product.getString("productId"), purchaseProductCategoryId)) {
                // a Purchase allow productCategoryId was found, but the product is not in the category, axe it...
                Debug.logWarning("Product [" + productId + "] is not in the purchase allow category [" + purchaseProductCategoryId + "] and cannot be purchased", module);
                product = null;
            }
        }
    } catch (GenericEntityException e) {
        Debug.logWarning(e.toString(), module);
        product = null;
    }

    if (product == null) {
        Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productId", productId);
        String excMsg = UtilProperties.getMessage(resource_error, "item.product_not_found", messageMap , locale);

        Debug.logWarning(excMsg, module);
        throw new ItemNotFoundException(excMsg);
    }
    return product;
}
 
開發者ID:gildaslemoal,項目名稱:elpi,代碼行數:30,代碼來源:ShoppingCartItem.java

示例10: getCategoryTrail

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
public static List<List<String>> getCategoryTrail(String productCategoryId, DispatchContext dctx) {
    return CategoryWorker.getCategoryRollupTrails(dctx.getDelegator(), productCategoryId, true);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:4,代碼來源:SolrCategoryUtil.java

示例11: getCategoryRollupTrails

import org.ofbiz.product.category.CategoryWorker; //導入依賴的package包/類
/**
 * Return all paths from the given topCategoryIds to the category.
 * <p>
 * TODO?: perhaps can cache with UtilCache in future, or read from a cached category tree.
 */
protected List<List<String>> getCategoryRollupTrails(Delegator delegator, String productCategoryId, Set<String> topCategoryIds) {
    return CategoryWorker.getCategoryRollupTrails(delegator, productCategoryId, topCategoryIds, true);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:9,代碼來源:SeoCatalogUrlWorker.java


注:本文中的org.ofbiz.product.category.CategoryWorker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。