首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查看产品类别树(分层视图)

查看产品类别树(分层视图)
EN

Stack Overflow用户
提问于 2016-09-27 01:08:12
回答 2查看 384关注 0票数 0

我有多个类别的产品存在。

示例:

代码语言:javascript
复制
Category > Books > Hardcover Books > childCategory
Category > Promo Books > Sample > childCategory

是否有任何辅助类可用于获取产品的所有类别的列表?

EN

回答 2

Stack Overflow用户

发布于 2016-09-27 03:24:40

据我所知,没有任何实用类OOTB可以为您提供产品的完整树结构。也就是说,构建它并不是太困难。

给定一个根,并假设您知道“根”categoryId,将以下方法添加到CatalogTools类的扩展中。

代码语言:javascript
复制
    private RqlStatement findParentCategoriesOfProductRQL;

    public RepositoryItem[] findParentCategoriesOfProduct(String productId, String rootCategoryId) throws RepositoryException {
        RepositoryView view = getCatalog().getView("category");
        RepositoryItem[] parentCategories = findParentCategoriesOfProductRQL.executeQuery(view, new Object[] {productId, rootCategoryId });
        if (parentCategories == null || parentCategories.length == 0) {
            return null;
        }
        return parentCategories;
    }

    public void setFindParentCategoriesOfProductRQL(RqlStatement findParentCategoriesOfProduct) {
        this.findParentCategoriesOfProductRQL = findParentCategoriesOfProduct;
    }

    public RqlStatement getFindParentCategoriesOfProductRQL() {
        return findParentCategoriesOfProductRQL;
    }

并将以下内容添加到您的CatalogTools.properties

代码语言:javascript
复制
findParentCategoriesOfProductRQL=fixedChildProducts includes item (id = ?0) AND ancestorCategoryIds includes ?1
票数 1
EN

Stack Overflow用户

发布于 2016-09-27 21:58:12

如果您使用CommerceReferenceStore (CRS)作为站点的基础,那么您的/atg/commerce/catalog/CatalogTools组件将使用StoreCatalogTools类,该类扩展了atg.commerce.catalog.custom.CustomCatalogTools类。否则,如果您的CatalogTools组件不使用CustomCatalogTools类,您将需要更新它以使其使用该类。

以下是可用的method

代码语言:javascript
复制
public java.util.Collection getProductsCategories(RepositoryItem pProduct,
                                         Repository pCatalogRepository)
                                           throws RepositoryException

您可以使用默认目录来调用它,如下所示:

代码语言:javascript
复制
getCatalogTools().getProductsCategories(productItem, getCatalog());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39708549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档