查看产品类别树(分层视图)
View product category tree (hierarchical view)
我有多个类别的产品。
示例:
Category > Books > Hardcover Books > childCategory
Category > Promo Books > Sample > childCategory
是否有任何帮助程序 类 可用于获取产品所有类别的列表?
我不知道有任何实用程序 classes OOTB 可以为您提供产品的完整树结构。也就是说,构建起来并不难。
给定一个 productId
并且假设您知道 'root' categoryId
,将以下方法添加到 CatalogTools
class 的扩展中。
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
findParentCategoriesOfProductRQL=fixedChildProducts includes item (id = ?0) AND ancestorCategoryIds includes ?1
如果您使用 CommerceReferenceStore (CRS) 作为站点的基础,那么您的 /atg/commerce/catalog/CatalogTools
组件将使用 StoreCatalogTools
class,它扩展了 atg.commerce.catalog.custom.CustomCatalogTools
class。否则,如果您的 CatalogTools
组件不使用 CustomCatalogTools
class,您将需要更新它以便它使用。
以下method可用:
public java.util.Collection getProductsCategories(RepositoryItem pProduct,
Repository pCatalogRepository)
throws RepositoryException
您可以像这样使用默认目录调用它:
getCatalogTools().getProductsCategories(productItem, getCatalog());
我有多个类别的产品。
示例:
Category > Books > Hardcover Books > childCategory
Category > Promo Books > Sample > childCategory
是否有任何帮助程序 类 可用于获取产品所有类别的列表?
我不知道有任何实用程序 classes OOTB 可以为您提供产品的完整树结构。也就是说,构建起来并不难。
给定一个 productId
并且假设您知道 'root' categoryId
,将以下方法添加到 CatalogTools
class 的扩展中。
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
findParentCategoriesOfProductRQL=fixedChildProducts includes item (id = ?0) AND ancestorCategoryIds includes ?1
如果您使用 CommerceReferenceStore (CRS) 作为站点的基础,那么您的 /atg/commerce/catalog/CatalogTools
组件将使用 StoreCatalogTools
class,它扩展了 atg.commerce.catalog.custom.CustomCatalogTools
class。否则,如果您的 CatalogTools
组件不使用 CustomCatalogTools
class,您将需要更新它以便它使用。
以下method可用:
public java.util.Collection getProductsCategories(RepositoryItem pProduct,
Repository pCatalogRepository)
throws RepositoryException
您可以像这样使用默认目录调用它:
getCatalogTools().getProductsCategories(productItem, getCatalog());