flamingo.me/flamingo-commerce/v3@v3.11.0/category/Readme.md (about) 1 # Category Module 2 3 * Domain Layer: Provides domain model for: 4 * (product)category with potential data a category can have (like name, media, ...) 5 * a (category) tree 6 * the related categoryService interface (= Secondary Port) 7 8 * Interface Layer: 9 * Provides controller for rendering category pages, supporting different templates based on the category type. 10 * Provides data controller to access category and tree from inside templates 11 12 * Product Search: 13 * Since it's expected that products should be shown, there is a dependency to the "product" module - more specific to the productSearchService. 14 * 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. 15 16 ## Configurations 17 18 You can set the templates for the category single view (if it should be different from default) 19 ```yaml 20 # default template 21 commerce.category.view.template: "category/category" 22 23 # template used for category type "teaser" 24 commerce.category.view.teaserTemplate: "category/teaser" 25 ``` 26 27 ## Usage in templates 28 This module provides two data controller that can be used to get category and tree objects: 29 ```pug 30 - var rootCategoryTree = data('category.tree', {'code': ''}) 31 32 each category in rootCategoryTree.categories 33 34 - var category = data("category",{'code': 'category-code'}) 35 ``` 36 37 ## Dependencies: 38 * product package: (for product searchservice) 39 * search package: (for pagination) 40 41 42 ## GraphQL 43 44 This module offers GraphQL Shema and Resolver to get Categories. 45 46 Example: 47 48 ```graphql 49 query category { 50 Commerce_Category(categoryCode:"flat-screen_tvs") { 51 category { 52 code 53 attributes { 54 all {code} 55 metaKeywords:get(code:"meta_keywords") {values{value}} 56 hasMetaKeywords: has(code:"meta_keywords") 57 } 58 } 59 productSearchResult { 60 products { 61 baseData {title} 62 } 63 } 64 } 65 } 66 ``` 67 68 69 ## Category tree from config 70 71 The module comes also with a Adapter for the secondary port "CategoryService" which can be activated by setting `commerce.category.useCategoryFixedAdapter: true` 72 You can then configure a category tree like in the example below. 73 74 (Of course this is only useful for small tests or demos) 75 76 ```yaml 77 commerce: 78 category: 79 useCategoryFixedAdapter: true 80 categoryServiceFixed: 81 tree: 82 electronics: 83 code: electronics 84 name: Electronics 85 sort: 1 86 childs: 87 flat-screen_tvs: 88 code: flat-screen_tvs 89 name: Flat Screens & TV 90 headphones: 91 code: headphones 92 name: Headphones 93 childs: 94 headphone_accessories: 95 code: headphone_accessories 96 name: Accessories 97 tablets: 98 code: tablets 99 name: Tablets 100 clothing: 101 code: clothing 102 name: Clothes & Fashion 103 sort: 2 104 ``` 105 106 ## Categories and category tree from json files 107 108 The module comes with another Adapter for the "CategoryService" which can be activated by setting `commerce.category.fakeService.enabled: true` 109 Per default the category tree and the extended data for the electronics category you can see below will be returned. 110 111 Default categoryTree.json: 112 ```json 113 [ 114 { 115 "CategoryCode": "electronics", 116 "CategoryName": "Electronics", 117 "CategoryPath": "Electronics", 118 "SubTreesData": [ 119 { 120 "CategoryCode": "flat-screen_tvs", 121 "CategoryName": "Flat Screens & TV", 122 "CategoryPath": "Electronics/Flat Screens & TV" 123 }, 124 { 125 "CategoryCode": "headphones", 126 "CategoryName": "Headphones", 127 "CategoryPath": "Electronics/Headphones", 128 "SubTreesData": [ 129 { 130 "CategoryCode": "headphone_accessories", 131 "CategoryName": "Accessories", 132 "CategoryPath": "Electronics/Headphones/Accessories" 133 } 134 ] 135 }, 136 { 137 "CategoryCode": "tablets", 138 "CategoryName": "Tablets", 139 "CategoryPath": "Electronics/Tablets" 140 } 141 ] 142 }, 143 { 144 "CategoryCode": "clothing", 145 "CategoryName": "Clothes & Fashion", 146 "CategoryPath": "Clothes & Fashion", 147 "SubTreesData": [ 148 { 149 "CategoryCode": "jumpsuits", 150 "CategoryName": "Jumpsuits", 151 "CategoryPath": "Clothes & Fashion/Jumpsuits" 152 } 153 ] 154 } 155 ] 156 ``` 157 Default electronics.json: 158 ```json 159 { 160 "CategoryCode": "electronics", 161 "CategoryName": "Electronics", 162 "CategoryPath": "Electronics", 163 "CategoryTypeCode": "promotion", 164 "IsPromoted": true, 165 "CategoryMedia": [ 166 { 167 "MediaType": "image", 168 "MediaMimeType": "image/png", 169 "MediaUsage": "promotion", 170 "MediaTitle": "Electronics", 171 "MediaReference": "electronics.png" 172 } 173 ], 174 "CategoryAttributes": { 175 "promo": { 176 "Code": "promo", 177 "Label": "Promotion" 178 } 179 }, 180 "Promotion": { 181 "LinkType": "application/pdf", 182 "LinkTarget": "blank", 183 "Media": [ 184 { 185 "MediaType": "pdf", 186 "MediaMimeType": "application/pdf", 187 "MediaUsage": "promotion", 188 "MediaTitle": "Electronics", 189 "MediaReference": "electronics.pdf" 190 } 191 ] 192 } 193 } 194 ``` 195 196 You can provide a path for json files that include the data for the categories and the tree via `commerce.category.fakeService.testDataFolder`. 197 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. 198 The json file for the category with the code `electronics` for example has to be named `electronics.json`. 199 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. 200