Category Module
Configurations
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"
Usage in templates
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'})
Dependencies:
- product package: (for product searchservice)
- search package: (for pagination)
GraphQL
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}
}
}
}
}
Category tree from config
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
Categories and category tree from json files
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.