Getting Started With SCAYLE
Create Shop Categories
- Getting started
- Tech
Robert Merten
VP Tech
In this section, we’ll cover the basic aspects of how to use the Storefront API on the homepage and for navigation. Additionally, we'll explore the creation and management of shop categories, an important part of product organization.
Shop categories in the SCAYLE Panel are crucial for structuring product relationships and organizing your storefront. Each category can be assigned any number of filters, making each one unique and recognizable to your customers. The purpose of categories is to simplify navigation in the storefront, creating a well-structured and organized way of presenting products.
By default, the category trees defined for each shop country can also be used as storefront navigation menus in the header section. If you need a customizable navigation structure independent of the shop country category tree, try using this feature.
After setting up the German and Swiss Fashion Store shops, defining and importing product data, and configuring warehouses, it's time to create shop categories. In the following section, we'll create a global category tree with the first shop category being "men." Then, we’ll create the subcategories "trousers" and "shirts." We'll also specify which products will be displayed in each category and which filters we can apply.
The category tree we’re setting up will be shared across all shop countries.
You’ll have the option to customize the visibility and state (activated/deactivated) of specific shop categories for each shop country later on.
Creating a global category.
In the “included product” section, we'll decide which products to display. You can either include or exclude certain product IDs or define criteria for the product set based on master categories and attribute groups.
Next, you’ll need to select at least one filter to create a shop category. Once you assign a simple attribute group to a filter, customers can use it on the shop’s frontend to filter the category pages.
Adding filter to global category.
Repeat the steps outlined above to create the "shirts" and "trousers" subcategories.
Created category with subcategory.
[note] Congratulations! You’ve just created your first global shop categories! [/note]
[tip] To view the products added to your category click “more” on the shop country level. This will open a new tab displaying the relevant product list.
Please note that general adjustments to the category (such as filters, included products, and category name) can only be made on the shared category tree. You can learn more about how to copy categories or change the order of the category tree here. [/tip]
Next, we'll adjust the global category tree to meet the requirements of the German and Swiss shop countries. Let's assume that the German Fashion Store wants to highlight the "men" category and the "shirts" subcategory in the storefront's navigation menu. The "trousers" subcategory will be active but is hidden in the navigation. In Switzerland, the category tree will look almost the same, but the "trousers" subcategory will be inactive.
By default, all newly created categories are inactive (shown in red), meaning that customers won’t be able to find them in the shop. If categories are displayed in green, they are active and therefore can be found in the shop as well as in the navigation. If categories are green and transparent, customers can access them via URLs, but they won't be visible in the navigation.
Let's configure the categories:
Activating subcategory Shirts.
Activated and hidden subcategories.
Now, let's follow the same steps for the Swiss shop country, with one key difference–the “trousers” category will remain inactive. After completing these steps, your final result should look like this:
Inactive subcategory.
[note] Great job! You’ve just created your first shop country categories! [/note]
Deleting categories
You can only delete a category from the category tree at the global level, not at the shop country level. However, on a shop country level, you can set a category to be "inactive" and "hidden." To delete a category globally which will affect all shop countries, follow these steps:
Delete Categories.
Well done! You are now able to adjust global and shop country category trees!
In this section, we’ll briefly cover the most important endpoints and best practices. Shop categories structure the shop assortment and provide additional information using specific properties. Find more on this topic here.
What is this endpoint for?
The bapiClient.categories.getRoots
function returns a list of root-level categories, including all its children if required. To retrieve a hidden category, you can include the parameter includeHidden: true
.
The Storefront Core provides a function called getRootCategories(...)
. This function fetches the data from Storefront Core API and additionally maps it to an object containing the categories and an activeNode
property.
The underlying API call fetches the root categories by utilizing the “categoryByPath” endpoint:
https://BAPI_HOST/categories?with=variants:all,attributes:all&campaignKey=CAMPAIGN_KEY
The path being /
.
The Storefront Core uses Redis caching for performance optimization. The Redis key set by the SFC is prefixed with root-categories
appended with the request hash. To view the data in your cache, use this cache key.
Here’s an example of SFC:
if (path === '/') {
return getRootCategories({ children, includeHidden }, ...)
}
The data retrieved from the Storefront Core might look something like this:
{
categories: [{
"id": 2045,
"path": "/women",
"name": "Women",
"slug": "women",
"description": "",
"parentId": 0,
"rootlineIds": [
2045
],
"childrenIds": [],
"properties": [],
"isHidden": false,
"depth": 1,
"supportedFilter": [
"color",
"size",
"brand",
"material"
],
"shopLevelCustomData": {},
"countryLevelCustomData": {},
"children": []
},...],
activeNode: undefined,
}
What is this endpoint for?
The bapiClient.categories.getById
function returns a single category along with all its parents and children, if needed. To retrieve a hidden category, you can pass includeHidden: true
.
SFC (Storefront Core) provides a function called getCategoryById(...)
in useCategories(...)
, which returns the data from Storefront Core API without any modification.
Here is an example using Storefront Core:
const {
getCategoryById,
} = useCategories('some-global-key')
onFetchAsync(async () => {
const category = await getCategoryById(1337)
if (!category) throw new Error('Category not found!')
})
The data comes straight from Storefront API, with no modifications happening in SFC.
{
"id": 2045,
"path": "/women",
"name": "Women",
"slug": "women",
"description": "",
"parentId": 0,
"rootlineIds": [
2045
],
"childrenIds": [],
"properties": [],
"isHidden": false,
"depth": 1,
"supportedFilter": [
"color",
"size",
"brand",
"material"
],
"shopLevelCustomData": {},
"countryLevelCustomData": {},
"children": []
}
Dev-to-Dev Hint
We recommend using getByPath
as it's easier for debugging. Instead of passing an ID, you’d pass the unique category path. For example, /men/clothing
instead of 2052
.
category ID could vary for different environments like integration, staging, and production.
If a URL from the CMS (Content Management System) contains an ID instead of a path, we can resolve it using the getById
method and return the corresponding path
.
const match = url.match(/\/categories\/(\d+)/)
if (!match) return
const [type, _id] = match
const id = parseInt(_id, 10)
return (
await context.cached(context.bapiClient.categories.getById)(id)
).path
With this method, a URL like https://fashion-store.com/store/de-de/c/121
becomes: https://fashion-store.com/store/de-de/c/bekleidung/poloshirts
Getting Started With SCAYLE
Robert Merten
VP Tech
Create side-navigation.