To support hierarchical searching on the product catalog, each category and product has a property called ancestorCategories
, whose value is a Set of categories that are higher in the catalog hierarchy than the given catalog or product.
Note: The data for the ancestorCategories
property must be updated whenever new categories or products are added to or deleted from the product catalog or when an existing category is modified to contain a different set of products or child categories. To update the data for the ancestorCategories
property, use the Nucleus component AncestorGeneratorService
:
In the Components > by Path window, select the
/atg/commerce/catalog/AncestorGeneratorService
component.Choose File > Open Component. The Component Editor opens.
If the component is not currently running, choose Component > Start Component.
Select the Methods tab.
Click the Invoke button next to the
generateAncestors
method.
The generateAncestors
method automatically updates the ancestorCategories
property for every product and category in the catalog. A message is displayed indicating that the method ran successfully.
Note that the Methods tab also includes methods called generateCategoryAncestors
(which generates the ancestorCategories
property for category items only) and generateProductAncestors
(which generates the ancestorCategories
property for product items only). The generateAncestors
method works by calling both of these methods.
You should regenerate the ancestor categories whenever the set of products or categories in the catalog changes. Generating ancestor categories can be time-consuming. Run the AncestorGeneratorService
only on the staging database, not the live database.
By default, the AncestorGeneratorService
component is configured to work with the standard catalog schema. It generates ancestor categories for the product and category item types, and stores the names of these ancestor categories in the ancestorCategories
property of each product and category.
If you are using a different schema, you can still use AncestorGeneratorService
to generate ancestor categories, provided that:
The catalog structure is hierarchical.
The catalog includes item types that represent categories and products (regardless of the actual names of these item types).
The item types representing categories and products each have a property for storing the names of ancestor categories (regardless of the name of the property; note, however, that the property must have the same name for each item type).
The GenerateAncestorService
generates ancestors for all categories, then ancestors for all products. This minimizes writing to the database; the service only needs to find the immediate category ancestor for any product, since the further ancestors of the category have already been determined.