-
Domain Layer: Provides domain model for:
- (product)category with potential data a category can have (like name, media, ...)
- a (category) tree
- the related categoryService interface (= Secondary Port)
-
Interface Layer:
- Provides controller for rendering category pages, supporting different templates based on the category type.
- Provides data controller to access category and tree from inside templates
-
Product Search:
- Since it's expected that products should be shown, there is a dependency to the "product" module - more specific to the productSearchService.
- The category module defines in its domain also a "CategoryFilter" (that implements the search filter interface): This filter is passed to the productSearchService, so any implementation of the product search service should understand this special filter.
You can set the templates for the category single view (if it should be different from default)
# default template
commerce.category.view.template: "category/category"
# template used for category type "teaser"
commerce.category.view.teaserTemplate: "category/teaser"
This module provides two data controller that can be used to get category and tree objects:
- var rootCategoryTree = data('category.tree', {'code': ''})
each category in rootCategoryTree.categories
- var category = data("category",{'code': 'category-code'})
- product package: (for product searchservice)
- search package: (for pagination)
This module offers GraphQL Shema and Resolver to get Categories.
Example:
query category {
Commerce_Category(categoryCode:"flat-screen_tvs") {
category {
code
attributes {
all {code}
metaKeywords:get(code:"meta_keywords") {values{value}}
hasMetaKeywords: has(code:"meta_keywords")
}
}
productSearchResult {
products {
baseData {title}
}
}
}
}
The module comes also with a Adapter for the secondary port "CategoryService" which can be activated by setting commerce.category.useCategoryFixedAdapter: true
You can then configure a category tree like in the example below.
(Of course this is only useful for small tests or demos)
commerce:
category:
useCategoryFixedAdapter: true
categoryServiceFixed:
tree:
electronics:
code: electronics
name: Electronics
sort: 1
childs:
flat-screen_tvs:
code: flat-screen_tvs
name: Flat Screens & TV
headphones:
code: headphones
name: Headphones
childs:
headphone_accessories:
code: headphone_accessories
name: Accessories
tablets:
code: tablets
name: Tablets
clothing:
code: clothing
name: Clothes & Fashion
sort: 2
The module comes with another Adapter for the "CategoryService" which can be activated by setting commerce.category.fakeService.enabled: true
Per default the category tree and the extended data for the electronics category you can see below will be returned.
Default categoryTree.json:
[
{
"CategoryCode": "electronics",
"CategoryName": "Electronics",
"CategoryPath": "Electronics",
"SubTreesData": [
{
"CategoryCode": "flat-screen_tvs",
"CategoryName": "Flat Screens & TV",
"CategoryPath": "Electronics/Flat Screens & TV"
},
{
"CategoryCode": "headphones",
"CategoryName": "Headphones",
"CategoryPath": "Electronics/Headphones",
"SubTreesData": [
{
"CategoryCode": "headphone_accessories",
"CategoryName": "Accessories",
"CategoryPath": "Electronics/Headphones/Accessories"
}
]
},
{
"CategoryCode": "tablets",
"CategoryName": "Tablets",
"CategoryPath": "Electronics/Tablets"
}
]
},
{
"CategoryCode": "clothing",
"CategoryName": "Clothes & Fashion",
"CategoryPath": "Clothes & Fashion",
"SubTreesData": [
{
"CategoryCode": "jumpsuits",
"CategoryName": "Jumpsuits",
"CategoryPath": "Clothes & Fashion/Jumpsuits"
}
]
}
]
Default electronics.json:
{
"CategoryCode": "electronics",
"CategoryName": "Electronics",
"CategoryPath": "Electronics",
"CategoryTypeCode": "promotion",
"IsPromoted": true,
"CategoryMedia": [
{
"MediaType": "image",
"MediaMimeType": "image/png",
"MediaUsage": "promotion",
"MediaTitle": "Electronics",
"MediaReference": "electronics.png"
}
],
"CategoryAttributes": {
"promo": {
"Code": "promo",
"Label": "Promotion"
}
},
"Promotion": {
"LinkType": "application/pdf",
"LinkTarget": "blank",
"Media": [
{
"MediaType": "pdf",
"MediaMimeType": "application/pdf",
"MediaUsage": "promotion",
"MediaTitle": "Electronics",
"MediaReference": "electronics.pdf"
}
]
}
}
You can provide a path for json files that include the data for the categories and the tree via commerce.category.fakeService.testDataFolder
.
The json file for the category tree has to be named categoryTree.json
. Files that represent a category have to be named after the code of the category.
The json file for the category with the code electronics
for example has to be named electronics.json
.
If you do not offer a json file for a category the basic data for the category will be taken from the categoryTree.json
instead.