io.sphere.sdk.meta.CategoryDocumentation Maven / Gradle / Ivy
package io.sphere.sdk.meta;
/**
Create a tree of categories
Lets suppose we want to create this category tree (the number before the name is the externalId):
{@doc.gen include file sphere-convenience/src/it/resources/category-tree-1.txt}
To define the category tree in a CSV format we start with the top level categories so that each parent category appears before its child categories:
{@doc.gen include file sphere-convenience/src/it/resources/category-import-1.csv}
Then we can write some script to parse the csv and create them in sphere:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#setUpData()}
Fetch all categories
Fetch all
If categories don't change often it is a good idea to just cache them.
You can use {@link io.sphere.sdk.queries.ExperimentalReactiveStreamUtils} to do this:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#fetchAll()}
Fetch all with predicate
Sometimes you want to fetch just the root categories to delete them all:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#fetchRoots()}
Work with a cached tree of categories
In Fetch all categories you read how to obtain all categories or categories matching a predicate.
The list of all categories is required to form a category tree:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#createCategoryTree()}
With a {@link io.sphere.sdk.categories.CategoryTree} you can find categories by slug, by ID and search categories by their parent.
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#simpleCategoryTreeOperations()}
Render a whole tree
{@include.example io.sphere.sdk.meta.CategoryTreeTextRepresentation}
Render a breadcrumb
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#createAViewForACategoryBreadCrumb()}
Render a partial tree
{@include.example io.sphere.sdk.meta.RenderAPartialTree}
Delete categories and trees
Removing a category also means to delete all child categories of this category:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#categoryDeletionIsRecursive()}
Change the category tree
It is possible to reorganize category trees by changing the reference to the parent category.
But it is not possible to transform a category with a parent to a root category. If you need this, you need to create a new category and move the subcategories there.
In the following example we move the mens-clothing category to the top category:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#moveCategoryTree()}
Find products in a category tree
In order to fetch products that belong to a category or to a category tree you specify the category IDs in the query predicate:
{@include.example io.sphere.sdk.meta.CategoryDocumentationTest#demoForFindProducts()}
*/
public class CategoryDocumentation {
private CategoryDocumentation() {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy