aboutyou-sdk 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/aboutyou-sdk/Model/Product.rb +273 -473
- data/tests/Sinatra-test/Main.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDZjYTljYjAzN2FkZGIwNWQ5MTYyM2Q5N2FiN2U0MGRiOGQ4ZDE3Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmQ2MTc4YTc3N2UwNjM2NjYwMjcwYjM1YzcwY2JkMTliMGNjMDA1Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTUxNjQwYzRhN2IwZjI1ZWVlZDAzMWU1NzI3YTY0NWI1NWJhYzE0OTExY2Jh
|
10
|
+
OTM5MzUyZTVjZjhkZGEwNWEzYWVkNGVkZjUxYTI4MDU4NmMyNGYxNDY3NTgz
|
11
|
+
ZDZkYjFhY2JhY2YzYzU5MjUwMTkwNzE0M2YwMTUyODY0YWZlMzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDc1MTU2Mzc4YTk1NWNkYzU5ZDg5MTcxOWQzY2RlMGE0MmRmYTAxZWZmMjhm
|
14
|
+
YzRhMWM0YTFlZDRhZjBlMzYwMDZmZTk0NzFlZmM0YjVkZTUyYjE5Y2U5ZDE0
|
15
|
+
YzFjYTQ1N2UwNzJiYjM0ZWQxNGU4Njc2YmJiMDJjNjY1ZTZlYjI=
|
@@ -4,532 +4,332 @@ module AboutYou
|
|
4
4
|
class Product
|
5
5
|
include AbstractModel
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
48
|
-
|
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.
|
56
|
-
product.
|
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.
|
63
|
-
product.
|
64
|
-
product.
|
65
|
-
product.
|
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.
|
68
|
-
product.
|
69
|
-
product.
|
70
|
-
product.
|
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
|
-
|
74
|
-
product.
|
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
|
-
|
66
|
+
key = 'categories.' + String(appId)
|
67
|
+
product.categoryIdPaths = jsonObject["key"] ? jsonObject["key"] : []
|
77
68
|
|
78
|
-
|
79
|
-
end
|
69
|
+
product.facetIds = product.parseFacetIds(jsonObject)
|
80
70
|
|
81
|
-
|
82
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
82
|
+
variants
|
83
|
+
end
|
93
84
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
102
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
100
|
+
if name.index('categories') === 0
|
101
|
+
paths = categoryPaths
|
102
|
+
break
|
103
|
+
end
|
113
104
|
end
|
114
|
-
return paths;
|
115
|
-
end
|
116
105
|
|
117
|
-
|
106
|
+
paths
|
107
|
+
end
|
118
108
|
|
119
|
-
|
120
|
-
|
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
|
-
|
112
|
+
ids = self.parseFacetIdsInVariants(jsonObject) if ids === null
|
130
113
|
|
131
|
-
|
132
|
-
return nil
|
133
|
-
end
|
114
|
+
ids = self.parseFacetIdsInBrand(jsonObject) if $ids === null
|
134
115
|
|
135
|
-
|
136
|
-
|
116
|
+
ids != nil ? ids : []
|
117
|
+
end
|
118
|
+
|
119
|
+
def parseFacetIdsInAttributesMerged(jsonObject)
|
120
|
+
return nil if jsonObject["attributes_merged"].empty?
|
137
121
|
|
138
|
-
|
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
|
-
|
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
|
-
|
131
|
+
# TODO: Remove Workaround for Ticket ???
|
132
|
+
facetIds = Array(facetIds)
|
133
|
+
ids[gid] = facetIds
|
134
|
+
end
|
153
135
|
|
154
|
-
|
155
|
-
|
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
|
-
|
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
|
-
|
153
|
+
end
|
169
154
|
|
170
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|
-
|
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
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
allGroups =
|
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
|
-
|
370
|
-
|
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
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
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
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
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
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
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
|
-
|
468
|
-
|
469
|
-
|
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
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
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
|
-
|
486
|
-
|
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
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
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
|
-
|
505
|
-
return variant;
|
506
|
-
end
|
307
|
+
variants.push(variant) if variant.ean == ean
|
507
308
|
end
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
-
|
527
|
-
variants.push(variant)
|
528
|
-
end
|
317
|
+
return variant if variant.facetGroupSet.uniqueKey == key
|
529
318
|
end
|
530
|
-
|
531
|
-
|
532
|
-
|
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
|
data/tests/Sinatra-test/Main.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|