aboutyou-sdk 0.0.9 → 0.0.10

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.
@@ -1,435 +1,468 @@
1
1
  module AboutYou
2
2
  module SDK
3
3
  module Criteria
4
+ ###
5
+ # This class is used as the criteria for a product search
6
+ # Its instance is meant to be passed to the fetchProducrSearch method
7
+ # To add a specific criteria simply call the method on the instance
8
+ #
9
+ # author:: Collins GmbH & Co KG
10
+ ###
4
11
  class ProductSearchCriteria
5
- SORT_TYPE_RELEVANCE = 'relevance';
6
- SORT_TYPE_UPDATED = 'updated_date';
7
- SORT_TYPE_CREATED = 'created_date';
8
- SORT_TYPE_MOST_VIEWED = 'most_viewed';
9
- SORT_TYPE_PRICE = 'price';
10
-
11
- SORT_ASC = 'asc';
12
- SORT_DESC = 'desc';
13
-
14
- FACETS_ALL = '_all';
15
- FACETS_UNLIMITED = -1;
16
-
17
- FILTER_SALE = 'sale';
18
- FILTER_CATEGORY_IDS = 'categories';
19
- FILTER_PRICE = 'prices';
20
- FILTER_SEARCHWORD = 'searchword';
21
- FILTER_ATTRIBUTES = 'facets';
22
-
23
- attr_accessor :filter
24
- attr_accessor :result
25
- attr_accessor :sessionId
26
-
27
- ###
28
- # @param string $sessionId
29
- ###
30
- def initialize(sessionId)
31
-
32
- self.filter = Hash.new
33
- self.sessionId = sessionId
34
- self.result = Hash.new
12
+ # api-call-name for sorting after relevance
13
+ SORT_TYPE_RELEVANCE = 'relevance'
14
+ # api-call-name for sorting after updated_date
15
+ SORT_TYPE_UPDATED = 'updated_date'
16
+ # api-call-name for sorting after created_date
17
+ SORT_TYPE_CREATED = 'created_date'
18
+ # api-call-name for sorting after most_viewed
19
+ SORT_TYPE_MOST_VIEWED = 'most_viewed'
20
+ # api-call-name for sorting after price
21
+ SORT_TYPE_PRICE = 'price'
22
+
23
+ # api-call-name for sorting ascending
24
+ SORT_ASC = 'asc'
25
+ # api-call-name for sorting descending
26
+ SORT_DESC = 'desc'
27
+
28
+ # api-call name for requiring all facets
29
+ FACETS_ALL = '_all'
30
+
31
+ # api-call-value for requiring unlimited facets
32
+ FACETS_UNLIMITED = -1
33
+
34
+ # api-call-name for filtering the sale
35
+ FILTER_SALE = 'sale'
36
+ # api-call-name for filtering the categories
37
+ FILTER_CATEGORY_IDS = 'categories'
38
+ # api-call-name for filtering the prices
39
+ FILTER_PRICE = 'prices'
40
+ # api-call-name for filtering the searchword
41
+ FILTER_SEARCHWORD = 'searchword'
42
+ # api-call-name for filtering the facets
43
+ FILTER_ATTRIBUTES = 'facets'
44
+
45
+ # the filter applied to the api-call
46
+ attr_accessor :filter
47
+ # a specification of the result which should be fetched from api
48
+ attr_accessor :result
49
+ # the session id of a user
50
+ attr_accessor :sessionId
51
+
52
+ ###
53
+ # Constructor for AboutYou::SDK::Criteria::ProductSearchCriteria
54
+ #
55
+ # * *Args* :
56
+ # - +sessionId+ -> the session is of an user
57
+ #
58
+ # * *Returns* :
59
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
60
+ ###
61
+ def initialize(sessionId)
62
+ self.filter = {}
63
+ self.sessionId = sessionId
64
+ self.result = {}
65
+ end
66
+
67
+ ###
68
+ # adds the filter passed to the api the given filter value
69
+ #
70
+ # * *Args* :
71
+ # - +key+ -> the name of the filter which should be applied
72
+ # - +value+ -> the value of the filter which should be applied
73
+ #
74
+ # * *Returns* :
75
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
76
+ ###
77
+ def filterBy(key, value)
78
+ filter[key] = value
79
+ return self
80
+ end
81
+
82
+ ###
83
+ # gets the filter value of a given filter key
84
+ #
85
+ # * *Args* :
86
+ # - +key+ -> the name of the filter which value should be returned
87
+ #
88
+ # * *Returns* :
89
+ # - either a value of a filter or nil if filter key not set
90
+ ###
91
+ def filter(key)
92
+ @filter[key] if @filter[key]
93
+ end
94
+
95
+ ###
96
+ # sets a filter for filtering by sale
97
+ #
98
+ # * *Args* :
99
+ # - +sale+ -> determines whether to filter by sale or not [optional]
100
+ #
101
+ # * *Returns* :
102
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
103
+ ###
104
+ def filterBySale(sale = true)
105
+ unless sale.is_a?(TrueClass) || sale.is_a?(FalseClass)
106
+ sale = nil
35
107
  end
36
108
 
37
-
38
- ###
39
- # @param string $key
40
- # @param string $value
41
- #
42
- # @return ProductSearchCriteria
43
- ###
44
- def filterBy(key, value)
45
-
46
- self.filter[key] = value
47
- return self
48
- end
49
-
50
- ###
51
- # @param string $key
52
- #
53
- # @return null|mixed
54
- ###
55
- def getFilter(key)
56
- if(self.filter[key])
57
- return self.filter[key]
58
- end
59
-
60
- return nil
61
- end
62
-
63
- ###
64
- # @param boolean|null $sale
65
- # true => only sale products
66
- # false => no sale products
67
- # null => both (default)
68
- #
69
- # @return ProductSearchCriteria
70
- ###
71
- def filterBySale(sale = true)
72
-
73
- if !(sale.is_a?(TrueClass) || sale.is_a?(FalseClass))
74
- sale = nil;
75
- end
76
-
77
- return self.filterBy(FILTER_SALE, sale);
78
- end
79
-
80
- ###
81
- # @return boolean|null
82
- ###
83
- def saleFilter()
84
-
85
- return self.filter(FILTER_SALE);
86
- end
87
-
88
- ###
89
- # @param string $searchword
90
- #
91
- # @return ProductSearchCriteria
92
- ###
93
- def filterBySearchword(searchword)
94
-
95
- return self.filterBy(FILTER_SEARCHWORD, searchword);
96
- end
97
-
98
- ###
99
- # @return string|null
100
- ###
101
- def searchwordFilter()
102
-
103
- return self.filter(FILTER_SEARCHWORD);
109
+ self.filterBy(FILTER_SALE, sale)
110
+ end
111
+
112
+ ###
113
+ # sets a filter for filtering by a searchword
114
+ #
115
+ # * *Args* :
116
+ # - +searchword+ -> the searchword which should be used for filtering
117
+ #
118
+ # * *Returns* :
119
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
120
+ ###
121
+ def filterBySearchword(searchword)
122
+ self.filterBy(FILTER_SEARCHWORD, searchword)
123
+ end
124
+
125
+ ###
126
+ # sets a filter for filtering by category ids
127
+ #
128
+ # * *Args* :
129
+ # - +categoryIds+ -> the category ids used for filtering
130
+ # - +append+ -> determines whether to append the category ids to an already set value or not [optional]
131
+ #
132
+ # * *Returns* :
133
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
134
+ ###
135
+ def filterByCategoryIds(categoryIds, append = false)
136
+ if append && self.filter[FILTER_CATEGORY_IDS]
137
+ categoryIds = self.filter[FILTER_CATEGORY_IDS] + categoryIds
104
138
  end
105
-
106
- ###
107
- # @param integer[] $categoryIds array of integer
108
- # @param boolean $append if true the category ids will added to current filter
109
- #
110
- # @return ProductSearchCriteria
111
- ###
112
- def filterByCategoryIds(categoryIds, append = false)
113
-
114
- if (append && self.filter[FILTER_CATEGORY_IDS])
115
- categoryIds = self.filter[FILTER_CATEGORY_IDS] + categoryIds
139
+ categoryIds = categoryIds.uniq
140
+
141
+ self.filterBy(FILTER_CATEGORY_IDS, categoryIds);
142
+ end
143
+
144
+
145
+ ###
146
+ # sets a filter for filtering by category ids
147
+ #
148
+ # * *Args* :
149
+ # - +attributes+ -> Array of Hashes containing the relation Group_Id => Facet_Id
150
+ # - +append+ -> determines whether to append the category ids to an already set value or not [optional]
151
+ #
152
+ # * *Returns* :
153
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
154
+ ###
155
+ def filterByFacetIds(attributes, append = false)
156
+ if append && self.filter[FILTER_ATTRIBUTES]
157
+ merged = self.filter[FILTER_ATTRIBUTES]
158
+ attributes.each do |groupId, facetIds|
159
+ if merged.key?(groupId)
160
+ merged[groupId] = (merged[groupId] + facetIds).uniq
161
+ else
162
+ merged[groupId] = facetIds
163
+ end
116
164
  end
117
- categoryIds = categoryIds.uniq
118
-
119
- return self.filterBy(FILTER_CATEGORY_IDS, categoryIds);
165
+ attributes = merged
120
166
  end
121
-
122
- ###
123
- # @return integer[]|null
124
- ###
125
- def categoryFilter()
126
-
127
- return self.filter(FILTER_CATEGORY_IDS)
128
- end
129
-
130
- ###
131
- # @param array $attributes array of array with group id and attribute ids
132
- # for example [0 => [264]]: search for products with the brand "TOM TAILER"
133
- # @param boolean $append, if true the category ids will added to current filter
134
- #
135
- # @return ProductSearchFilter
136
- ###
137
- def filterByFacetIds(attributes, append = false)
138
167
 
139
- if (append && self.filter[FILTER_ATTRIBUTES])
140
- merged = self.filter[FILTER_ATTRIBUTES];
141
- attributes.each do |groupId, facetIds|
142
- if (merged.key?(groupId))
143
- merged[groupId] = (merged[groupId] + facetIds).uniq;
144
- else
145
- merged[groupId] = facetIds;
146
- end
147
- end
148
-
149
- attributes = merged;
150
- end
151
- return self.filterBy(FILTER_ATTRIBUTES, attributes);
152
- end
153
-
154
- ###
155
- # @return array|null
156
- # @see filterByFacetIds()
157
- ###
158
- def facetFilter()
159
-
160
- return self.filter(FILTER_ATTRIBUTES);
161
- end
162
-
163
- ###
164
- # @param FacetGroup $facetGroup
165
- # @param boolean $append, if true the category ids will added to current filter
166
- #
167
- # @return ProductSearchCriteria
168
- ###
169
- def filterByFacetGroup(facetGroup, append = false)
170
-
171
- return self.filterByFacetIds(facetGroup.ids(), append);
172
- end
173
-
174
- ###
175
- # @param FacetGroupSet $facetGroupSet
176
- # @param boolean $append, if true the category ids will added to current filter
177
- #
178
- # @return ProductSearchCriteria
179
- ###
180
- def filterByFacetGroupSet(facetGroupSet, append = false)
181
-
182
- return self.filterByFacetIds(facetGroupSet.ids(), append);
183
- end
184
-
185
- ###
186
- # @param integer $from must be 1 or greater
187
- # @param integer $to must be 1 or greater
188
- #
189
- # @return ProductSearchCriteria
190
- ###
191
- def filterByPriceRange(from = 0, to = 0)
192
-
193
- from = Integer(from)
194
- to = Integer(to)
195
-
196
- price = Hash.new;
197
- if (from > 0)
198
- price["from"] = from
199
- end
200
- if (to > 0)
201
- price["to"] = to
202
- end
203
-
204
- return self.filterBy(FILTER_PRICE, price);
205
- end
206
-
207
- ###
208
- # Returns an associative array with could contains "to" and/or "from", eg.
209
- # ["from" => 100, "to" => 10000] or ["to" => 20000]
210
- #
211
- # @return array|null
212
- ###
213
- def priceRangeFilter()
214
-
215
- return self.filter(FILTER_PRICE);
216
- end
217
-
218
- ###
219
- # @param string $type
220
- # @param string $direction
221
- #
222
- # @return $this
223
- ###
224
- def sortBy(type, direction = SORT_ASC)
225
-
226
- self.result['sort'] = Hash[
227
- 'by' => type,
228
- 'direction' => direction,
229
- ]
230
-
231
- return self;
232
- end
233
-
234
- ###
235
- # @param integer $limit
236
- # @param integer $offset
237
- #
238
- # @return $this
239
- ##
240
- def setLimit(limit, offset = 0)
241
-
242
- limit = [[limit, 200].min, 0].max
243
- self.result['limit'] = limit
244
-
245
- offset = [offset, 0].max;
246
- self.result['offset'] = offset
247
-
248
- return self;
249
- end
250
-
251
- ###
252
- # @param bool $enable
253
- #
254
- # @return $this
255
- ###
256
- def selectSales(enable = true)
257
-
258
- if (enable)
259
- self.result['sale'] = true
260
- else
261
- self.result['sale'] = nil
262
- end
263
-
264
- return self;
265
- end
266
-
267
- ###
268
- # @param bool $enable
269
- #
270
- # @return $this
271
- ###
272
- def selectPriceRanges(enable = true)
273
-
274
- if (enable)
275
- self.result['price'] = true
276
- else
277
- self.result['price'] = nil
278
- end
279
-
280
- return self;
281
- end
282
-
283
- ###
284
- # @param integer|string $groupId
285
- # @param integer $limit
286
- #
287
- # @return $this
288
- #
289
- # @throws \InvalidArgumentException
290
- ###
291
- def selectFacetsByGroupId(groupId, limit)
292
-
293
- self.checkFacetLimit(limit);
294
- if (!(groupId.is_a? Fixnum) && (Integer(groupId)).nil?)
295
- raise InvalidArgumentException();
296
- end
297
-
298
- if (!self.result['facets'])
299
- self.result['facets'] = Hash.new
300
- end
301
-
302
- if !(self.result['facets'][groupId])
303
- self.result['facets'][String(groupId)] = Hash['limit' => limit];
304
- end
305
- return self;
168
+ self.filterBy(FILTER_ATTRIBUTES, attributes)
169
+ end
170
+
171
+
172
+ ###
173
+ # sets a filter for filtering by Facet-Group
174
+ #
175
+ # * *Args* :
176
+ # - +facetGroup+ -> Instance of AboutYou::SDK::Model::FacetGroup
177
+ # - +append+ -> determines whether to append the category ids to an already set value or not [optional]
178
+ #
179
+ # * *Returns* :
180
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
181
+ ###
182
+ def filterByFacetGroup(facetGroup, append = false)
183
+ self.filterByFacetIds(facetGroup.ids, append)
184
+ end
185
+
186
+ ###
187
+ # sets a filter for filtering by Facet-Groupset
188
+ #
189
+ # * *Args* :
190
+ # - +facetGroupSet+ -> Instance of AboutYou::SDK::Model::FacetGroupSet
191
+ # - +append+ -> determines whether to append the category ids to an already set value or not [optional]
192
+ #
193
+ # * *Returns* :
194
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
195
+ ###
196
+ def filterByFacetGroupSet(facetGroupSet, append = false)
197
+ self.filterByFacetIds(facetGroupSet.ids, append)
198
+ end
199
+
200
+ ###
201
+ # sets a filter for filtering by Price range
202
+ #
203
+ # * *Args* :
204
+ # - +from+ -> states the starting value of the price filter
205
+ # - +to+ -> states the end value of the price filter
206
+ #
207
+ # * *Returns* :
208
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
209
+ ###
210
+ def filterByPriceRange(from = 0, to = 0)
211
+ from = Integer(from)
212
+ to = Integer(to)
213
+ price = {}
214
+
215
+ price["from"] = from if from > 0
216
+ price["to"] = to if to > 0
217
+
218
+ self.filterBy(FILTER_PRICE, price)
219
+ end
220
+
221
+ ###
222
+ # sets a sorting-filter and direction
223
+ #
224
+ # * *Args* :
225
+ # - +type+ -> states the type of the sorting
226
+ # - +direction+ -> the direction of the sorting [optional]
227
+ #
228
+ # * *Returns* :
229
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
230
+ ###
231
+ def sortBy(type, direction = SORT_ASC)
232
+ self.result['sort'] = {
233
+ 'by' => type,
234
+ 'direction' => direction,
235
+ }
236
+ self
237
+ end
238
+
239
+ ###
240
+ # sets a limit and offset for the product search
241
+ #
242
+ # * *Args* :
243
+ # - +limit+ -> limits the amount of results received from the api
244
+ # - +offset+ -> sets an offset to skip results [optional]
245
+ #
246
+ # * *Returns* :
247
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
248
+ ###
249
+ def setLimit(limit, offset = 0)
250
+ limit = [[limit, 200].min, 0].max
251
+ self.result['limit'] = limit
252
+
253
+ offset = [offset, 0].max
254
+ self.result['offset'] = offset
255
+ self
256
+ end
257
+
258
+ ###
259
+ # this method determines whether you receive only sales products or not
260
+ #
261
+ # * *Args* :
262
+ # - +enable+ -> if true api will return only sales products [optional]
263
+ #
264
+ # * *Returns* :
265
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
266
+ ###
267
+ def selectSales(enable = true)
268
+ if enable
269
+ self.result['sale'] = true
270
+ else
271
+ self.result['sale'] = nil
306
272
  end
307
-
308
- ###
309
- # @param FacetGetGroupInterface $group
310
- # @param integer $limit
311
- #
312
- # @return $this
313
- ###
314
- def selectFacetsByFacetGroup(group, limit)
315
-
316
- return self.selectFacetsByGroupId(group.getGroupId(), limit);
273
+
274
+ self
275
+ end
276
+
277
+ ###
278
+ # this method determines whether you receive price ranges or not
279
+ #
280
+ # * *Args* :
281
+ # - +enable+ -> if true api will return price ranges [optional]
282
+ #
283
+ # * *Returns* :
284
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
285
+ ###
286
+ def selectPriceRanges(enable = true)
287
+ if enable
288
+ self.result['price'] = true
289
+ else
290
+ self.result['price'] = nil
317
291
  end
318
292
 
319
- ###
320
- # @param integer $limit
321
- #
322
- # @return $this
323
- ###
324
- def selectAllFacets(limit)
325
-
326
- self.checkFacetLimit(limit);
327
- self.result['facets'] = Hash[self::FACETS_ALL => Hash['limit' => limit]];
328
-
329
- return self;
293
+ self
294
+ end
295
+
296
+ ###
297
+ # this method adds a field to the api-request which enables you to
298
+ # receive Facets by a given group id
299
+ #
300
+ # * *Args* :
301
+ # - +groupId+ -> group id which facets you want to receive
302
+ # - +limit+ -> limits the received facets
303
+ #
304
+ # * *Returns* :
305
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
306
+ ###
307
+ def selectFacetsByGroupId(groupId, limit)
308
+ self.checkFacetLimit(limit)
309
+ unless groupId.is_a?(Fixnum) && Integer(groupId)
310
+ raise "InvalidArgumentException! Group id must be an integer or a
311
+ string containing digits"
330
312
  end
331
-
332
- def checkFacetLimit(limit)
333
-
334
- if !((limit.is_a? Fixnum) || (limit.is_a? Integer))
335
- raise InvalidArgumentException('limit must be an integer');
336
- end
337
- if (limit < -1)
338
- raise InvalidArgumentException('limit must be positive or -1 for unlimited facets');
339
- end
313
+ unless self.result['facets']
314
+ self.result['facets'] = {}
340
315
  end
341
-
342
- ###
343
- # @param bool $enable
344
- #
345
- # @return $this
346
- ###
347
- def selectCategories(enable = true)
348
-
349
- if (enable)
350
- self.result['categories'] = true;
351
- else
352
- self.result['categories'] = nil;
353
- end
354
-
355
- return self;
316
+ unless self.result['facets'][groupId]
317
+ self.result['facets'][String(groupId)] = {'limit' => limit}
356
318
  end
357
-
358
- ###
359
- # @param integer|Product[] $ids
360
- #
361
- # @return $this
362
- ###
363
- def boostProducts(ids)
364
-
365
- ids = ids.map{
366
- |val|
367
- if val.instance_of? Product
368
- return val.getId()
369
- end
370
- return Integer(val)
371
- }
372
- ids = ids.uniq;
373
- self.result['boosts'] = ids;
374
-
375
- return self;
319
+
320
+ self
321
+ end
322
+
323
+ ###
324
+ # this method will make the api return all facets
325
+ #
326
+ # * *Args* :
327
+ # - +limit+ -> limits the received facets
328
+ #
329
+ # * *Returns* :
330
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
331
+ ###
332
+ def selectAllFacets(limit)
333
+ self.checkFacetLimit(limit)
334
+ self.result['facets'] = {self::FACETS_ALL => {'limit' => limit}}
335
+
336
+ self
337
+ end
338
+
339
+ ###
340
+ # this method checks whether a given facet limit is valid or not
341
+ #
342
+ # * *Args* :
343
+ # - +limit+ -> limit which should be checked
344
+ #
345
+ # * *Returns* :
346
+ # - nil if there is no error
347
+ ###
348
+ def checkFacetLimit(limit)
349
+ unless limit.is_a?(Fixnum) || limit.is_a?(Integer)
350
+ raise 'InvalidArgumentException! limit must be an integer'
376
351
  end
377
-
378
- ###
379
- # @param string[] $fields
380
- #
381
- # @return $this
382
- ###
383
- def selectProductFields(fields)
384
-
385
- self.result['fields'] = AboutYou::SDK::Criteria::ProductFields.filterFields(fields);
386
-
387
- return self;
352
+ if limit < -1
353
+ raise 'InvalidArgumentException! limit must be positive or -1 for unlimited facets'
388
354
  end
389
-
390
- ###
391
- # @param string $sessionId
392
- #
393
- # @return $this
394
- #
395
- def setSessionId(sessionId)
396
-
397
- self.sessionId = sessionId;
398
-
399
- return self;
355
+ end
356
+
357
+ ###
358
+ # this method lets the api return the categories if stated so
359
+ #
360
+ # * *Args* :
361
+ # - +enable+ -> determines whether or not the categories should be received from the api [optional]
362
+ #
363
+ # * *Returns* :
364
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
365
+ ###
366
+ def selectCategories(enable = true)
367
+ if enable
368
+ self.result['categories'] = true
369
+ else
370
+ self.result['categories'] = nil
400
371
  end
401
-
402
- def requiresCategories()
403
-
404
- productCategories = (self.result.has_key?('fields') && AboutYou::SDK::Criteria::ProductFields.requiresCategories(self.result['fields']))
405
- categoryFacets = (self.result.has_key?('categories') && self.result['categories'])
406
372
 
407
- return (productCategories || categoryFacets)
373
+ self
374
+ end
375
+
376
+ ###
377
+ # this method lets the api return products. It will prefer to return
378
+ # products which are given by +ids+
379
+ #
380
+ # * *Args* :
381
+ # - +ids+ -> the products which should be boosted or the ids of them
382
+ #
383
+ # * *Returns* :
384
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
385
+ ###
386
+ def boostProducts(ids)
387
+ mappedIds = []
388
+ ids = ids.map{
389
+ |val|
390
+ if val.instance_of?(Product)
391
+ mappedIds.push(val.id)
392
+ end
393
+ mappedIds.push(val)
394
+ }
395
+ mappedIds = mappedIds.uniq
396
+ self.result['boosts'] = ids
397
+
398
+ self
399
+ end
400
+
401
+ ###
402
+ # this method lets you select certain
403
+ # AboutYou::SDK::Criteria::ProductFields which will be returned from api
404
+ #
405
+ # * *Args* :
406
+ # - +fields+ -> an Array of constants from AboutYou::SDK::Criteria::ProductFields
407
+ #
408
+ # * *Returns* :
409
+ # - an instance of AboutYou::SDK::Criteria::ProductSearchCriteria
410
+ ###
411
+ def selectProductFields(fields)
412
+ self.result['fields'] =
413
+ AboutYou::SDK::Criteria::ProductFields.filterFields(fields)
414
+
415
+ self
416
+ end
417
+
418
+ ###
419
+ # this method decides whether categories are required to fetch from api
420
+ #
421
+ # * *Returns* :
422
+ # - a boolean stating whether to fetch categories from api or not
423
+ ###
424
+ def requiresCategories
425
+ (self.result.has_key?('fields') &&
426
+ AboutYou::SDK::Criteria::ProductFields.
427
+ requiresCategories(self.result['fields'])) ||
428
+ (self.result.has_key?('categories') &&
429
+ self.result['categories'])
430
+ end
431
+
432
+ ###
433
+ # this method decides whether facets are required to fetch from api
434
+ #
435
+ # * *Returns* :
436
+ # - a boolean stating whether to fetch facets from api or not
437
+ ###
438
+ def requiresFacets
439
+ (self.result.key?('fields') &&
440
+ AboutYou::SDK::Criteria::ProductFields.
441
+ requiresFacets(self.result['fields'])) ||
442
+ (self.result.key?('facets') &&
443
+ !self.result['facets'].empty?)
444
+ end
445
+
446
+ ###
447
+ # this method turns an instance of
448
+ # AboutYou::SDK::Criteria::productSearchCriteria in an Array which can
449
+ # be passed directly to the api
450
+ #
451
+ # * *Returns* :
452
+ # - an Array containing all the parameters set on the instance
453
+ ###
454
+ def toArray
455
+ params = {'session_id' => self.sessionId}
456
+
457
+ if self.result
458
+ params['result'] = self.result
408
459
  end
409
-
410
- def requiresFacets()
411
-
412
- productFacets = (self.result.key?('fields') && AboutYou::SDK::Criteria::ProductFields.requiresFacets(self.result['fields']))
413
- facetFacets = (self.result.key?('facets') && !self.result['facets'].empty?)
414
- return (productFacets || facetFacets)
460
+ unless @filter.empty?
461
+ params['filter'] = self.filter
415
462
  end
416
463
 
417
- ###
418
- # @return array
419
- ###
420
- def toArray()
421
-
422
- params = Hash['session_id' => self.sessionId]
423
-
424
- if !(self.result.empty?)
425
- params['result'] = self.result;
426
- end
427
- if (self.filter)
428
- params['filter'] = self.filter;
429
- end
430
-
431
- return params;
432
- end
464
+ params
465
+ end
433
466
  end
434
467
  end
435
468
  end