aboutyou-sdk 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjE0NzJjNmJjNzUxMWEyMzA4OGE4NDUxYzFjMDc1NzhmNTI1MTE0Yg==
4
+ MDZjYTljYjAzN2FkZGIwNWQ5MTYyM2Q5N2FiN2U0MGRiOGQ4ZDE3Ng==
5
5
  data.tar.gz: !binary |-
6
- NDdhMzIxNzM5OTdmMmMxZGI2YzBiOThkNTk5OTc2NDkyMThjMjMzNA==
6
+ MmQ2MTc4YTc3N2UwNjM2NjYwMjcwYjM1YzcwY2JkMTliMGNjMDA1Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjRkMWY0ODQyNWYzOTFlMTY5MjhhOWMxNmRjN2I2N2EyMTMxMmZjY2Y0NDBl
10
- OGRmYTI0YmJiNmIwZWQzOWZjZmM3MTJhM2E0M2M1OTZkMDg1NWMyZDliNDcz
11
- MzdkY2Y1YWEyOGZlNWIzZGIzOGQ1Y2I5OGM1MzE1OTFlNDk2N2E=
9
+ OTUxNjQwYzRhN2IwZjI1ZWVlZDAzMWU1NzI3YTY0NWI1NWJhYzE0OTExY2Jh
10
+ OTM5MzUyZTVjZjhkZGEwNWEzYWVkNGVkZjUxYTI4MDU4NmMyNGYxNDY3NTgz
11
+ ZDZkYjFhY2JhY2YzYzU5MjUwMTkwNzE0M2YwMTUyODY0YWZlMzA=
12
12
  data.tar.gz: !binary |-
13
- Njk4Mjg0MDJlMThjNDdiZmNiZjRhODFlMmEzZjc1NTc5MjQ4NWQwNDFlYWY3
14
- ZDY4YTBmM2QwYzRlNmY1MWUzYTA5ZDZhNmFkNjcyODdmMGEzYWY5MmU1NGQw
15
- MDY5ODIwZmYzMDI2M2EwNWQzZTYxNjQyNjUzYjY4ZmNhYWQ4OWU=
13
+ NDc1MTU2Mzc4YTk1NWNkYzU5ZDg5MTcxOWQzY2RlMGE0MmRmYTAxZWZmMjhm
14
+ YzRhMWM0YTFlZDRhZjBlMzYwMDZmZTk0NzFlZmM0YjVkZTUyYjE5Y2U5ZDE0
15
+ YzFjYTQ1N2UwNzJiYjM0ZWQxNGU4Njc2YmJiMDJjNjY1ZTZlYjI=
@@ -4,532 +4,332 @@ module AboutYou
4
4
  class Product
5
5
  include AbstractModel
6
6
 
7
- attr_accessor :id
8
- attr_accessor :factory
9
- attr_accessor :name
10
- attr_accessor :isSale
11
- attr_accessor :isActive
12
- attr_accessor :descriptionShort
13
- attr_accessor :descriptionLong
14
- attr_accessor :minPrice
15
- attr_accessor :maxPrice
16
- attr_accessor :maxSavingsPrice
17
- attr_accessor :maxSavings
18
- attr_accessor :maxSavingsPercentage
19
- attr_accessor :brandId
20
- attr_accessor :merchantId
21
- attr_accessor :categoryIdPaths
22
- attr_accessor :facetIds
23
- attr_accessor :defaultImage
24
- attr_accessor :defaultVariant
25
- attr_accessor :selectedVariant
26
- attr_accessor :variants
27
- attr_accessor :inactiveVariants
28
- attr_accessor :styles
29
- attr_accessor :facetGroups
30
- attr_accessor :rootCategories
31
- attr_accessor :activeRootCategories
32
- attr_accessor :leafCategories
33
- attr_accessor :activeLeafCategories
34
-
35
- ###
36
- # @param $jsonObject
37
- # @param ModelFactoryInterface $factory
38
- #
39
- # @return static
40
- #
41
- # @throws \Collins\ShopApi\Exception\MalformedJsonException
42
- ###
43
- def self.createFromJson(jsonObject, factory, appId)
44
-
45
- product = self.new
7
+ attr_accessor :id
8
+ attr_accessor :factory
9
+ attr_accessor :name
10
+ attr_accessor :isSale
11
+ attr_accessor :isActive
12
+ attr_accessor :descriptionShort
13
+ attr_accessor :descriptionLong
14
+ attr_accessor :minPrice
15
+ attr_accessor :maxPrice
16
+ attr_accessor :maxSavingsPrice
17
+ attr_accessor :maxSavings
18
+ attr_accessor :maxSavingsPercentage
19
+ attr_accessor :brandId
20
+ attr_accessor :merchantId
21
+ attr_accessor :categoryIdPaths
22
+ attr_accessor :facetIds
23
+ attr_accessor :defaultImage
24
+ attr_accessor :defaultVariant
25
+ attr_accessor :selectedVariant
26
+ attr_accessor :variants
27
+ attr_accessor :inactiveVariants
28
+ attr_accessor :styles
29
+ attr_accessor :facetGroups
30
+ attr_accessor :rootCategories
31
+ attr_accessor :activeRootCategories
32
+ attr_accessor :leafCategories
33
+ attr_accessor :activeLeafCategories
34
+
35
+
36
+ def createFromJson(jsonObject, factory, appId)
37
+ product = self.new(jsonObject, factory)
38
+
46
39
  # these are required fields
47
- if (!jsonObject["id"] || !jsonObject["name"])
48
- raise 'MalformedJsonException'
49
- end
40
+ raise 'MalformedJsonException!' unless jsonObject["id"] || jsonObject["name"]
41
+
50
42
  product.factory = factory
51
-
52
- product.id = jsonObject["id"]
53
- product.name = jsonObject["name"]
54
43
 
55
- product.isSale = jsonObject["sale"] ? jsonObject["sale"] : false;
56
- product.descriptionShort = jsonObject["description_short"] ? jsonObject["description_short"] : '';
57
- product.descriptionLong = jsonObject["description_long"] ? jsonObject["description_long"] : '';
58
- product.isActive = jsonObject["active"] ? jsonObject["active"] : true;
59
- product.brandId = jsonObject["brand_id"] ? jsonObject["brand_id"] : nil;
60
- product.merchantId = jsonObject["merchant_id"] ? jsonObject["merchant_id"] : nil;
44
+ product.id = jsonObject["id"]
45
+ product.name = jsonObject["name"]
61
46
 
62
- product.minPrice = jsonObject["min_price"] ? jsonObject["min_price"] : nil;
63
- product.maxPrice = jsonObject["max_price"] ? jsonObject["max_price"] : nil;
64
- product.maxSavingsPrice = jsonObject["max_savings"] ? jsonObject["max_savings"] : nil;
65
- product.maxSavingsPercentage = jsonObject["max_savings_percentage"] ? jsonObject["max_savings_percentage"] : nil;
47
+ product.isSale = jsonObject["sale"] ? jsonObject["sale"] : false
48
+ product.descriptionShort = jsonObject["description_short"] ? jsonObject["description_short"] : ''
49
+ product.descriptionLong = jsonObject["description_long"] ? jsonObject["description_long"] : ''
50
+ product.isActive = jsonObject["active"] ? jsonObject["active"] : true
51
+ product.brandId = jsonObject["brand_id"] ? jsonObject["brand_id"] : nil
52
+ product.merchantId = jsonObject["merchant_id"] ? jsonObject["merchant_id"] : nil
66
53
 
67
- product.defaultImage = jsonObject["default_image"] ? factory.createImage(jsonObject["default_image"]) : nil
68
- product.defaultVariant = jsonObject["default_variant"] ? factory.createVariant(jsonObject["default_variant"], product) : nil;
69
- product.variants = parseVariants(jsonObject, factory, product);
70
- product.inactiveVariants = parseVariants(jsonObject, factory, product, 'inactive_variants');
71
- product.styles = parseStyles(jsonObject, factory);
54
+ product.minPrice = jsonObject["min_price"] ? jsonObject["min_price"] : nil
55
+ product.maxPrice = jsonObject["max_price"] ? jsonObject["max_price"] : nil
56
+ product.maxSavingsPrice = jsonObject["max_savings"] ? jsonObject["max_savings"] : nil
57
+ product.maxSavingsPercentage = jsonObject["max_savings_percentage"] ? jsonObject["max_savings_percentage"] : nil
72
58
 
73
- key = 'categories.' + String(appId)
74
- product.categoryIdPaths = jsonObject[key] ? jsonObject[key] : Array(nil);
59
+ product.defaultImage = jsonObject["default_image"] ? jsonObject["default_image"] : nil
60
+ product.defaultVariant = jsonObject["default_variant"] ? jsonObject["default_variant"] : nil
61
+
62
+ product.variants = product.parseVariants(jsonObject, factory, product)
63
+ product.inactiveVariants = product.parseVariants(jsonObject, factory, product, 'inactive_variants')
64
+ product.styles = product.parseStyles(jsonObject, factory)
75
65
 
76
- product.facetIds = product.parseFacetIds(jsonObject);
66
+ key = 'categories.' + String(appId)
67
+ product.categoryIdPaths = jsonObject["key"] ? jsonObject["key"] : []
77
68
 
78
- return product;
79
- end
69
+ product.facetIds = product.parseFacetIds(jsonObject)
80
70
 
81
- def self.parseVariants(jsonObject, factory, product, attributeName = 'variants')
82
- variants = Array(nil);
83
- if (jsonObject[attributeName])
84
- jsonObject[attributeName].each do |jsonVariant|
85
- variants.push(factory.createVariant(jsonVariant, product))
86
- end
87
- end
71
+ product
72
+ end
88
73
 
89
- return variants;
90
- end
74
+ def parseVariants(jsonObject, factory, product, attributeName = 'variants')
75
+ variants = {}
76
+ unless jsonObject[attributeName].empty?
77
+ jsonObject["attributeName"].each do |jsonVariant|
78
+ variants[jsonVariant["id"]] = factory.createVariant(jsonVariant, product)
79
+ end
80
+ end
91
81
 
92
- def self.parseStyles(jsonObject, factory)
82
+ variants
83
+ end
93
84
 
94
- styles = Array(nil);
95
- if (jsonObject["styles"])
96
- jsonObject["styles"].each do |style|
97
- styles.push(factory.createProduct(style))
98
- end
85
+ def parseStyles(jsonObject, factory)
86
+ styles = []
87
+ unless jsonObject["styles"].empty?
88
+ jsonObject["styles"].each do |style|
89
+ styles.push(factory.createProduct(style))
90
+ end
99
91
  end
100
92
 
101
- return styles;
102
- end
93
+ styles
94
+ end
95
+
96
+ def parseCategoryIdPaths(jsonObject)
97
+ paths = []
103
98
 
104
- def parseCategoryIdPaths(jsonObject)
105
-
106
- paths = Array(nil);
107
-
108
99
  jsonObject.each do |name, categoryPaths|
109
- if (name.index('categories') == 0)
110
- paths = categoryPaths;
111
- break;
112
- end
100
+ if name.index('categories') === 0
101
+ paths = categoryPaths
102
+ break
103
+ end
113
104
  end
114
- return paths;
115
- end
116
105
 
117
- def parseFacetIds(jsonObject)
106
+ paths
107
+ end
118
108
 
119
- ids = self.parseFacetIdsInAttributesMerged(jsonObject);
120
- if (ids === nil)
121
- ids = self.parseFacetIdsInVariants(jsonObject);
122
- end
123
- if (ids === nil)
124
- ids = self.parseFacetIdsInBrand(jsonObject);
125
- end
126
- return (ids != nil) ? ids : Array(nil);
127
- end
109
+ def parseFacetIds(jsonObject)
110
+ ids = self.parseFacetIdsInAttributesMerged(jsonObject)
128
111
 
129
- def parseFacetIdsInAttributesMerged(jsonObject)
112
+ ids = self.parseFacetIdsInVariants(jsonObject) if ids === null
130
113
 
131
- if (!jsonObject["attributes_merged"])
132
- return nil
133
- end
114
+ ids = self.parseFacetIdsInBrand(jsonObject) if $ids === null
134
115
 
135
- parseAttributesJson(jsonObject["attributes_merged"]);
136
- end
116
+ ids != nil ? ids : []
117
+ end
118
+
119
+ def parseFacetIdsInAttributesMerged(jsonObject)
120
+ return nil if jsonObject["attributes_merged"].empty?
137
121
 
138
- def parseAttributesJson(attributesJsonObject)
139
-
122
+ self.parseAttributesJson(jsonObject["attributes_merged"])
123
+ end
124
+
125
+ def parseAttributesJson(attributesJsonObject)
140
126
  ids = {}
141
-
127
+
142
128
  attributesJsonObject.each do |group, facetIds|
143
- gid = group[11..group.length] # prefix "attributes"
144
-
145
- # TODO: Remove Workaround for Ticket ???
146
- facetIds = Array(facetIds)
147
- ids[gid] = facetIds;
148
- end
149
- return ids
150
- end
129
+ gid = group[11..group.length] # rm prefix "attributes"
151
130
 
152
- def parseFacetIdsInVariants(jsonObject)
131
+ # TODO: Remove Workaround for Ticket ???
132
+ facetIds = Array(facetIds)
133
+ ids[gid] = facetIds
134
+ end
153
135
 
154
- if (jsonObject["variants"])
155
- ids = []
156
- jsonObject["variants"].each do |variant|
157
- ids.push(parseAttributesJson(variant["attributes"]))
158
- end
159
- ids = AboutYou::SDK::Model::FacetGroupSet.mergeFacetIds(ids)
160
- return ids
161
- elsif (jsonObject["default_variant"])
162
- ids = parseAttributesJson(jsonObject["default_variant"]["attributes"])
136
+ ids
137
+ end
163
138
 
164
- return ids
139
+ def parseFacetIdsInVariants(jsonObject)
140
+ if jsonObject["variants"]
141
+ ids = []
142
+ jsonObject["variants"].each do |variant|
143
+ ids.push(self.parseAttributesJson(variant["attributes"]))
144
+ end
145
+ ids = AboutYou::SDK::Model::FacetGroupSet.mergeFacetIds(ids)
146
+ return ids
147
+ elsif jsonObject["default_variant"]
148
+ ids = self.parseAttributesJson(jsonObject["default_variant"]["attributes"])
149
+ return ids
165
150
  end
166
151
 
167
152
  nil
168
- end
153
+ end
169
154
 
170
- def parseFacetIdsInBrand(jsonObject)
171
-
172
- unless jsonObject["brand_id"]
173
- return nil
174
- end
175
-
176
- Hash['0' => jsonObject["brand_id"]];
177
- end
178
-
179
-
180
- def generateFacetGroupSet()
181
-
182
- if (self.facetIds.empty?)
183
- raise 'ShopApi\Exception\RuntimeException! To use this method, you must add the field ProductFields::ATTRIBUTES_MERGED to the "product search" or "products by ids"'
184
- end
185
- self.facetGroups = AboutYou::SDK::Model::FacetGroupSet.new(self.facetIds);
186
- end
187
-
188
- ###
189
- # @return FacetGroupSet|null
190
- ###
191
- def facetGroupSet()
192
-
193
- unless @facetGroups
194
- generateFacetGroupSet
195
- end
196
- @facetGroups
197
- end
198
-
199
- ###
200
- # Returns the first active category and, if non active, then it return the first category
201
- #
202
- # @param bool $activeOnly return only categories that are active
203
- #
204
- # @return Category|null
205
- ###
206
- def category(active = true)
207
-
208
- if (self.categoryIdPaths.empty?)
209
- return;
210
- end
211
-
212
- self.leafCategories(active)[0]
213
- end
214
-
215
- ###
216
- # @return Category|null
217
- ###
218
- def categoryWithLongestActivePath()
219
-
220
- if (self.categoryIdPaths.empty?)
221
- return nil;
222
- end
155
+ def parseFacetIdsInBrand(jsonObject)
156
+ return nil unless jsonObject["brand_id"]
223
157
 
224
- sortedArray = self.categoryIdPaths
225
- sortedArray.sort!{|x,y| y.count <=> x.count}
226
- sortedArray.each do |path|
227
- if(self.factory.categoryManager.category(path[-1]).isPathActive)
228
- return self.factory.categoryManager.category(path[-1])
229
- end
158
+ {'0' => [jsonObject["brand_id"]]}
159
+ end
160
+
161
+ def generateFacetGroupSet
162
+ raise 'RuntimeException! To use this method, you must add the field ProductFields::ATTRIBUTES_MERGED to the "product search" or "products by ids"' if self.facetIds.empty?
163
+
164
+ self.facetGroups = AboutYou::SDK::Model::FacetGroupSet.new(self.facetIds)
165
+ end
166
+
167
+ def facetGroupSet
168
+ self.generateFacetGroupSet unless self.faceGroups
169
+
170
+ self.facetGroups
171
+ end
172
+
173
+
174
+ def category(active = false)
175
+ return nil unless self.categoryIdPaths
176
+
177
+ categories = self.leafCategories(active)
178
+ end
179
+
180
+ def categoryWithLongestActivePath
181
+
182
+ return nil unless self.categoryIdPaths
183
+
184
+ self.categoryIdPaths.sort!{|x,y| y.count <=> x.count}.each do |path|
185
+ return self.factory.categoryManager.category(path[-1]) if self.factory.categoryManager.category(path[-1]).isPathActive
230
186
  end
231
- return nil;
232
- end
233
-
234
- ###
235
- # Returns array of categories without subcategories. E.g. of the product is in the category
236
- # Damen > Schuhe > Absatzschuhe and Damen > Schuhe > Stiefelleten then
237
- # [Absatzschuhe, Stiefelleten] will be returned
238
- #
239
- # @param bool $activeOnly return only categories that are active
240
- #
241
- # @return Category[]
242
- ###
243
- def leafCategories(activeOnly = true)
244
-
245
- self.fetchAndParseCategories()
246
-
247
- activeOnly ? self.activeLeafCategories : self.leafCategories
248
- end
249
-
250
- def categories(activeOnly = true)
251
-
252
- return self.rootCategories(activeOnly);
253
- end
254
-
255
- ###
256
- # @param bool $activeOnly return only active categories
257
- #
258
- # @return Category[]
259
- ###
260
- def rootCategories(activeOnly = true)
261
-
262
- fetchAndParseCategories();
263
-
264
- activeOnly ? @activeRootCategories : @rootCategories
265
- end
266
-
267
- def fetchAndParseCategories()
268
-
269
- if (@rootCategories != nil)
270
- return;
271
- end
272
-
273
- self.rootCategories = Array(nil);
274
- self.activeRootCategories = Array(nil);
275
- self.leafCategories = Array(nil);
276
- self.activeLeafCategories = Array(nil);
277
-
278
- if (self.categoryIdPaths.empty?)
279
- return;
280
- end
281
-
282
- # put all category ids in an array to fetch by ids
283
- categoryIds = self.categoryIdPaths.uniq
284
-
285
- # fetch all necessary categories from API
286
- flattenCategories = self.shopApi().fetchCategoriesByIds(categoryIds).categories;
287
-
288
- flattenCategories.each do |category|
289
- parentId = category.parentId
290
- if (parentId != nil && flattenCategories[parentId])
291
- category.setParent(flattenCategories[parentId], true);
292
- end
293
- end
294
-
187
+ nil
188
+ end
189
+
190
+ def leafCategories(activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
191
+ self.factory.categoryManager.categories(self.leafCategoryIds, activeOnly)
192
+ end
193
+
194
+
195
+ def rootCategoryIds
196
+ rootCategories = []
295
197
  self.categoryIdPaths.each do |categoryIdPath|
296
- rootId = categoryIdPath[0];
297
- rootCategory = flattenCategories[rootId];
298
- self.rootCategories[rootId] = rootCategory;
299
- if (rootCategory.isActive)
300
- self.activeRootCategories[rootId] = rootCategory;
301
- end
302
-
303
- leafId = categoryIdPath[-1];
304
- leafCategory = flattenCategories[leafId];
305
- self.leafCategories[leafId] = leafCategory;
306
- if (leafCategory.isActive)
307
- self.activeLeafCategories[leafId] = leafCategory;
308
- end
309
- end
310
- end
311
-
312
-
313
- ###
314
- # Get facets of given group id.
315
- #
316
- # @param integer $groupId The group id.
317
- #
318
- # @return \Collins\ShopApi\Model\Facet[]
319
- ###
320
- def groupFacets(groupId)
321
-
322
- group = self.facetGroupSet.group(groupId);
323
- if (group)
324
- return group.facets;
198
+ rootCategories.push(categoryIdPath[0])
325
199
  end
326
- return Array(nil);
327
- end
328
-
329
- ###
330
- # Returns all unique FacetGroups from all Variants
331
- #
332
- # @param integer $groupId
333
- #
334
- # @return FacetGroup[]
335
- ###
336
- def facetGroups(groupId)
337
-
338
- allGroups = Array(nil);
339
- self.variants.each do |variant|
340
- groups = variant.facetGroupSet.groups;
341
- groups.each do |group|
342
- if (group.id == groupId)
343
- allGroups[group.uniqueKey] = group;
344
- end
345
- end
200
+
201
+ rootCategories.uniq
202
+ end
203
+
204
+ def leafCategoryIds
205
+ leafCategories = []
206
+ self.categoryIdPaths.each do |categoryIdPath|
207
+ leafCategories.push(categoryIdPath[-1])
346
208
  end
347
-
348
- return allGroups;
349
- end
350
-
351
- ###
352
- # Returns all FacetGroups, which matches the current facet group set
353
- # for example:
354
- # [['color'] => 'rot'] =>
355
- #
356
- # @param FacetGroupSet $selectedFacetGroupSet
357
- #
358
- # @return FacetGroup[][]
359
- #
360
- # @throws \Collins\ShopApi\Exception\RuntimeException
361
- ###
362
- def selectableFacetGroups(selectedFacetGroupSet)
363
-
364
- # @var FacetGroup[] $allGroups */
365
- allGroups = Array(nil);
366
- selectedGroupIds = selectedFacetGroupSet.groupIds();
367
-
209
+
210
+ leafCategories.uniq
211
+ end
212
+
213
+ def categories(activeOnly = AboutYou::SDK::Model::Category::ACTIVE_ONLY)
214
+ self.rootCategories(activeOnly)
215
+ end
216
+
217
+ def rootCategories(activeOnly = Category::ACTIVE_ONLY)
218
+ self.factory.categoryManager.categories(self.rootCategoryIds, activeOnly)
219
+ end
220
+
221
+ def groupFacets(groupId)
222
+ return group.facets if self.facetGroupSet.group(groupId)
223
+ []
224
+ end
225
+
226
+ def facetGroups(groupId)
227
+ allGroups = {}
368
228
  self.variants.each do |variant|
369
- facetGroupSet = variant.facetGroupSet();
370
- ids = facetGroupSet.groupIds();
371
-
372
- if (facetGroupSet.contains(selectedFacetGroupSet))
373
- ids.each do |groupId|
374
- if (selectedGroupIds.include?(groupId))
375
- continue;
376
- end
377
-
378
- group = facetGroupSet.group(groupId);
379
- if (group == nil)
380
- raise 'RuntimeException! group for id ' + String(groupId) + ' not found'
381
- end
382
- allGroups[groupId][group.uniqueKey()] = group;
383
- end
384
- end
385
- end
386
-
387
- selectedGroupIds.each do |groupId|
388
- ids = selectedFacetGroupSet.ids();
389
- ids[groupId] = nil
390
- myFacetGroupSet = FacetGroupSet.new(ids);
391
- self.variants.each do |variant|
392
- facetGroupSet = variant.facetGroupSet();
393
- if (facetGroupSet.contains(myFacetGroupSet))
394
- group = facetGroupSet.group(groupId);
395
- allGroups[groupId][group.uniqueKey()] = group;
396
- end
397
- end
229
+ variant.facetGroupSet.groups.each do |group|
230
+ allGroups[group.uniqueKey] = group if group.id === groupId
231
+ end
398
232
  end
399
-
400
- return allGroups;
401
- end
402
-
403
- ###
404
- # Returns all FacetGroups, which matches the current facet group set
405
- # for example:
406
- # [['color'] => 'rot'] =>
407
- #
408
- # @param FacetGroupSet $selectedFacetGroupSet
409
- #
410
- # @return FacetGroup[]
411
- ###
412
- def excludedFacetGroups(selectedFacetGroupSet)
413
-
414
- # @var FacetGroup[] $allGroups */
415
- allGroups = Array(nil);
416
- selectedGroupIds = selectedFacetGroupSet.groupIds();
417
-
233
+
234
+ allGroups
235
+ end
236
+
237
+ def selectableFacetGroups(selectedFacetGroupSet)
238
+ allGroups = {}
239
+
418
240
  self.variants.each do |variant|
419
- facetGroupSet = variant.facetGroupSet();
420
- if (!facetGroupSet.contains(selectedFacetGroupSet))
421
- continue;
422
- end
423
-
424
- ids = facetGroupSet.groupIds();
425
-
241
+ facetGroupSet = variant.facetGroupSet
242
+ ids = facetGroupSet.groupIds
243
+
244
+ if facetGroupSet.contains(selectedFacetGroupSet)
426
245
  ids.each do |groupId|
427
- if (selectedGroupIds.include?(groupId))
428
- continue;
429
- end
430
-
431
- group = facetGroupSet.group(groupId);
432
- if (group == nil)
433
- raise 'RuntimeException! group for id ' + String(groupId) + ' not found'
434
- end
435
- facets = group.facets();
436
- if (facets.empty?)
437
- continue;
438
- end
439
-
440
- if (allGroups[groupId])
441
- allGroups[groupId] = FacetGroup.new(group.id(), group.name());
442
- end
443
- allGroups[groupId].addFacets(facets);
246
+ next if selectedFacetGroupSet.groupIds.include?(groupId)
247
+ group = facetGroupSet.group(groupId)
248
+ raise 'RuntimeException! group for id ' + String(groupId) + ' not found' if group === nil
249
+
250
+ allGroups[groupId] = {group.uniqueKey => group}
444
251
  end
252
+ end
445
253
  end
446
-
447
- return allGroups;
448
- end
449
-
450
-
451
- ###
452
- # @return \Collins\ShopApi\Model\Facet
453
- ###
454
- def brand()
455
- self.facetGroupSet().facet(AboutYou::SDK::Constants::FACET_BRAND, self.brandId);
456
- end
457
-
458
- ###
459
- # Get variant by id.
460
- #
461
- # @param integer $variantId The variant id.
462
- #
463
- # @return Variant
464
- ###
465
- def variantById(variantId)
466
254
 
467
- self.variants.each do |variant|
468
- if (variant.id==variantId)
469
- return variant
255
+ selectedFacetGroupSet.groupIds.each do |groupId|
256
+ selectedFacetGroupSet.ids[groupId] = nil
257
+ self.variants.each do |variant|
258
+ facetGroupSet = variant.facetGroupSet
259
+ allGroups[groupId] = {group.uniqueKey => facetGroupSet.group(groupId)} if facetGroupSet.contains(AboutYou::SDK::Model::FacetGroupSet.new(ids))
470
260
  end
471
261
  end
472
-
473
- return nil;
474
- end
475
-
476
- ###
477
- # @param string $ean
478
- #
479
- # @return Variant[]
480
- ###
481
- def variantsByEan(ean)
482
-
483
- variants = Array(nil);
262
+
263
+ allGroups
264
+ end
265
+
266
+
267
+ def excludedFacetGroups(selectedFacetGroupSet)
268
+ allGroups = {}
269
+ selectedGroupIds = selectedFacetGroupSet.groupIds
270
+
484
271
  self.variants.each do |variant|
485
- if (variant.ean == ean)
486
- variants.push(variant);
272
+ facetGroupSet = variant.facetGroupSet
273
+ next unless facetGroupSet.contains(selectedFacetGroupSet)
274
+
275
+ facetGroupSet.groupIds.each do |groupId|
276
+ next if selectedFacetGroupSet.groupIds.include?(groupId)
277
+
278
+ group = facetGroupSet.group(groupId)
279
+ raise 'RuntimeException! group for id ' + String(groupId) + ' not found' if group == nil
280
+
281
+ facets = group.facets
282
+ next unless facets
283
+
284
+ unless allGroups[groupId]
285
+ allGroups[groupId] = AboutYou::SDK::Model::FacetGroup.new(group.id, group.name)
286
+ allGroups[groupId].addFacets(facets)
487
287
  end
288
+ end
488
289
  end
489
-
490
- return variants;
491
- end
492
-
493
- ###
494
- # This returns the first variant, which matches exactly the given facet group set
495
- #
496
- # @param FacetGroupSet $facetGroupSet
497
- #
498
- # @return Variant|null
499
- ###
500
- def variantByFacets(facetGroupSet)
501
-
502
- key = facetGroupSet.uniqueKey();
290
+
291
+ allGroups
292
+ end
293
+
294
+
295
+ def brand
296
+ self.facetGroupSet.facet(AboutYou::SDK::Constants::FACET_BRAND, self.brandId)
297
+ end
298
+
299
+ def variantById(variantId)
300
+ self.variants[variantId] ? self.variants[variantId] : nil
301
+ end
302
+
303
+
304
+ def variantsByEan(ean)
305
+ variants = []
503
306
  self.variants.each do |variant|
504
- if (variant.facetGroupSet().uniqueKey() == key)
505
- return variant;
506
- end
307
+ variants.push(variant) if variant.ean == ean
507
308
  end
508
-
509
- return nil;
510
- end
511
-
512
-
513
- ###
514
- # This returns all variants, which matches some of the given facet
515
- #
516
- # @param $facetId
517
- # @param $groupId
518
- #
519
- # @return Variant[]
520
- ###
521
- def variantsByFacetId(facetId, groupId)
522
-
523
- variants = Array(nil);
524
- facet = Facet.new(facetId, '', '', groupId, '');
309
+
310
+ variants
311
+ end
312
+
313
+
314
+ def variantByFacets(facetGroupSet)
315
+ key = facetGroupSet.uniqueKey
525
316
  self.variants.each do |variant|
526
- if (variant.facetGroupSet().contains(facet))
527
- variants.push(variant)
528
- end
317
+ return variant if variant.facetGroupSet.uniqueKey == key
529
318
  end
530
-
531
- return variants;
532
- end
319
+
320
+ nil
321
+ end
322
+
323
+
324
+ def variantsByFacetId(facetId, groupId)
325
+ variants = []
326
+ facet = AboutYou::SDK::Facet.new(facetId, '', '', groupId, '')
327
+ self.variants.each do |variant|
328
+ variants.push(variant) if variant.facetGroupSez.contains(facet)
329
+ end
330
+
331
+ variants
332
+ end
533
333
  end
534
334
  end
535
335
  end
@@ -1,5 +1,5 @@
1
1
  require 'sinatra'
2
2
 
3
3
  get "/" do
4
- erb :'docExampleProducts'
4
+ erb :testDocExample
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aboutyou-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferenc Beutel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty