2016-09-26 111 views
0

我有多個類別中存在的產品。查看產品類別樹(分層視圖)

例子:

Category > Books > Hardcover Books > childCategory 
Category > Promo Books > Sample > childCategory 

是否有可以用來獲得所有類別的產品的列表中的任何輔助類?

回答

1

我不知道任何實用程序類OOTB將爲您提供產品的完整樹結構。也就是說,建立這個並不困難。

給定一個productId,假設您知道「根」categoryId,請將以下方法添加到CatalogTools類的擴展中。

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 
+0

感謝您的反饋。我將查看您的代碼和CatalogTools。 – dreboy

+0

有沒有辦法只使用目錄工具來做到這一點? http://docs.oracle.com/cd/E52191_01/Platform.11-1/apidoc/atg/commerce/catalog/CatalogTools.html#getAncestors(atg.repository.RepositoryItem) – dreboy

+0

從文檔看起來它可能會你想要什麼。也許下一個類到'CustomCatalogTools'類,看看它在那裏提供了什麼。也許更具體。 http://docs.oracle.com/cd/E52191_01/Platform.11-1/apidoc/atg/commerce/catalog/custom/CustomCatalogTools.html#getAncestors(atg.repository.RepositoryItem) – radimpe

0

如果您使用的是CommerceReferenceStore(CRS)爲您的網站的基礎上,那麼你的/atg/commerce/catalog/CatalogTools組件使用StoreCatalogTools類,它擴展了atg.commerce.catalog.custom.CustomCatalogTools類。否則,如果您的CatalogTools組件不使用CustomCatalogTools類,則需要對其進行更新以便它可以執行。

以下method可用:

public java.util.Collection getProductsCategories(RepositoryItem pProduct, 
             Repository pCatalogRepository) 
              throws RepositoryException 

你可以使用默認的目錄,這樣稱呼它:

getCatalogTools().getProductsCategories(productItem, getCatalog());