aboutyou-sdk 0.0.1
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 +15 -0
- data/lib/aboutyou-sdk.rb +545 -0
- data/lib/aboutyou-sdk/Client.rb +125 -0
- data/lib/aboutyou-sdk/Constants.rb +48 -0
- data/lib/aboutyou-sdk/Criteria/ProductFields.rb +54 -0
- data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +436 -0
- data/lib/aboutyou-sdk/Factory/DefaultModelFactory.rb +454 -0
- data/lib/aboutyou-sdk/Model/AbstractModel.rb +26 -0
- data/lib/aboutyou-sdk/Model/App.rb +35 -0
- data/lib/aboutyou-sdk/Model/Autocomplete.rb +92 -0
- data/lib/aboutyou-sdk/Model/Basket.rb +262 -0
- data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +76 -0
- data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +100 -0
- data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +192 -0
- data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +46 -0
- data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +137 -0
- data/lib/aboutyou-sdk/Model/CategoriesResult.rb +15 -0
- data/lib/aboutyou-sdk/Model/Category.rb +126 -0
- data/lib/aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb +172 -0
- data/lib/aboutyou-sdk/Model/CategoryTree.rb +35 -0
- data/lib/aboutyou-sdk/Model/Facet.rb +105 -0
- data/lib/aboutyou-sdk/Model/FacetGroup.rb +110 -0
- data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +247 -0
- data/lib/aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb +79 -0
- data/lib/aboutyou-sdk/Model/Image.rb +134 -0
- data/lib/aboutyou-sdk/Model/ImageSize.rb +21 -0
- data/lib/aboutyou-sdk/Model/InitiateOrder.rb +50 -0
- data/lib/aboutyou-sdk/Model/Order.rb +17 -0
- data/lib/aboutyou-sdk/Model/Product.rb +543 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +125 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb +26 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +38 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb +49 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +58 -0
- data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +27 -0
- data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +43 -0
- data/lib/aboutyou-sdk/Model/ProductsResult.rb +52 -0
- data/lib/aboutyou-sdk/Model/ResultError.rb +24 -0
- data/lib/aboutyou-sdk/Model/Variant.rb +255 -0
- data/lib/aboutyou-sdk/Model/VariantsResult.rb +102 -0
- data/lib/aboutyou-sdk/Query.rb +261 -0
- data/lib/aboutyou-sdk/QueryBuilder.rb +440 -0
- data/tests/Sinatra-test/Main.rb +5 -0
- data/tests/testApiClient.rb +35 -0
- data/tests/testAutocomplete.rb +40 -0
- data/tests/testCatFilter.rb +35 -0
- data/tests/testCatTree.rb +37 -0
- data/tests/testFacets.rb +36 -0
- data/tests/testProdCatLongestPath.rb +34 -0
- data/tests/testProductSearchResult.rb +35 -0
- data/tests/testProductsByIds.rb +34 -0
- data/tests/testVariantsByIds.rb +34 -0
- metadata +122 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
module AboutYou
|
2
|
+
module SDK
|
3
|
+
class Client
|
4
|
+
|
5
|
+
API_END_POINT_STAGE = 'http://shop-api.staging.aboutyou.de/api';
|
6
|
+
API_END_POINT_SANDBOX = 'http://shop-api.sandbox.aboutyou.de/api';
|
7
|
+
API_END_POINT_LIVE = 'https://shop-api.aboutyou.de/api';
|
8
|
+
|
9
|
+
###
|
10
|
+
# @param string $appId
|
11
|
+
# @param string $appPassword
|
12
|
+
# @param string $apiEndPoint
|
13
|
+
# @param LoggerInterface $logger
|
14
|
+
###
|
15
|
+
def initialize(appId, appPassword, apiEndPoint = 'stage', logger = nil)
|
16
|
+
|
17
|
+
self.setAppCredentials(appId, appPassword);
|
18
|
+
self.setApiEndpoint(apiEndPoint);
|
19
|
+
end
|
20
|
+
|
21
|
+
###
|
22
|
+
# @param string $appId the app id for client authentication
|
23
|
+
# @param string $appPassword the app password/token for client authentication.
|
24
|
+
###
|
25
|
+
def setAppCredentials(appId, appPassword)
|
26
|
+
|
27
|
+
@appId = appId;
|
28
|
+
@appPassword = appPassword;
|
29
|
+
end
|
30
|
+
|
31
|
+
###
|
32
|
+
# @return string
|
33
|
+
###
|
34
|
+
def getApiEndPoint()
|
35
|
+
|
36
|
+
@apiEndPoint;
|
37
|
+
end
|
38
|
+
|
39
|
+
###
|
40
|
+
# @param string $apiEndPoint the endpoint can be the string 'stage' or 'live',
|
41
|
+
# then the default endpoints will be used or
|
42
|
+
# an absolute url
|
43
|
+
###
|
44
|
+
def setApiEndpoint(apiEndPoint)
|
45
|
+
|
46
|
+
case
|
47
|
+
when apiEndPoint=='stage'
|
48
|
+
@apiEndPoint = API_END_POINT_STAGE;
|
49
|
+
when apiEndPoint=='sandbox'
|
50
|
+
@apiEndPoint = API_END_POINT_SANDBOX;
|
51
|
+
when apiEndPoint=='live'
|
52
|
+
@apiEndPoint = API_END_POINT_LIVE;
|
53
|
+
else
|
54
|
+
@apiEndPoint = apiEndPoint;
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
###
|
60
|
+
# @return string
|
61
|
+
###
|
62
|
+
def getPageId()
|
63
|
+
|
64
|
+
@pageId;
|
65
|
+
end
|
66
|
+
|
67
|
+
###
|
68
|
+
# @param string $pageId
|
69
|
+
###
|
70
|
+
def setPageId(pageId)
|
71
|
+
|
72
|
+
@pageId = pageId;
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
###
|
77
|
+
# Builds a JSON string representing the request data via Guzzle.
|
78
|
+
# Executes the API request.
|
79
|
+
#
|
80
|
+
# @param string $body the queries as json string
|
81
|
+
#
|
82
|
+
# @return \Guzzle\Http\Message\Response response object
|
83
|
+
#
|
84
|
+
# @throws ApiErrorException will be thrown if response was invalid
|
85
|
+
###
|
86
|
+
def request(body)
|
87
|
+
|
88
|
+
if (@pageId)
|
89
|
+
request = {
|
90
|
+
:body=>body,
|
91
|
+
:basic_auth => { :username => @appId , :password => @appPassword},
|
92
|
+
:headers => { 'Content-Type' => 'application/json',
|
93
|
+
'Accept-Encoding' => 'gzip,deflate',
|
94
|
+
'X-Page-ID'=> @pageId }
|
95
|
+
}
|
96
|
+
else
|
97
|
+
request = {
|
98
|
+
:body=>body,
|
99
|
+
:basic_auth => { :username => @appId , :password => @appPassword},
|
100
|
+
:headers => { 'Content-Type' => 'application/json',
|
101
|
+
'Accept-Encoding' => 'gzip,deflate' }
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
response = HTTParty.post("https://shop-api.aboutyou.de/api",request)
|
106
|
+
begin
|
107
|
+
if (!((response.code >= 200 && response.code < 300) || response.code == 304))
|
108
|
+
raise response.code().to_s
|
109
|
+
end
|
110
|
+
begin
|
111
|
+
if (response.is_a? Array)
|
112
|
+
raise 'result is not array'
|
113
|
+
end
|
114
|
+
rescue
|
115
|
+
raise
|
116
|
+
end
|
117
|
+
rescue
|
118
|
+
raise
|
119
|
+
end
|
120
|
+
|
121
|
+
return JSON.parse(response.body)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
###
|
2
|
+
# Contains often used properties related to the App development.
|
3
|
+
#
|
4
|
+
# @author Antevorte GmbH
|
5
|
+
###
|
6
|
+
module AboutYou
|
7
|
+
module SDK
|
8
|
+
module Constants
|
9
|
+
SDK_VERSION = 0.1;
|
10
|
+
FACET_BRAND = 0;
|
11
|
+
FACET_COLOR = 1;
|
12
|
+
FACET_SIZE = 2;
|
13
|
+
FACET_GENDERAGE = 3;
|
14
|
+
FACET_CUPSIZE = 4;
|
15
|
+
FACET_LENGTH = 5;
|
16
|
+
FACET_DIMENSION3 = 6;
|
17
|
+
FACET_SIZE_CODE = 206;
|
18
|
+
FACET_SIZE_RUN = 172;
|
19
|
+
FACET_CLOTHING_UNISEX_INT = 173;
|
20
|
+
FACET_CLOTHING_UNISEX_INCH = 174;
|
21
|
+
FACET_SHOES_UNISEX_EUR = 194;
|
22
|
+
FACET_CLOTHING_WOMEN_DE = 175;
|
23
|
+
FACET_CLOTHING_UNISEX_ONESIZE = 204;
|
24
|
+
FACET_SHOES_UNISEX_ADIDAS_EUR = 195;
|
25
|
+
FACET_CLOTHING_WOMEN_BELTS_CM = 181;
|
26
|
+
FACET_CLOTHING_WOMEN_INCH = 180;
|
27
|
+
FACET_CLOTHING_MEN_BELTS_CM = 190;
|
28
|
+
FACET_CLOTHING_MEN_INCH = 189;
|
29
|
+
FACET_CLOTHING_MEN_DE = 187;
|
30
|
+
FACET_CONDITION = 234;
|
31
|
+
FACET_QUANTITY_PER_PACK = 263;
|
32
|
+
FACET_SEASON_CODE = 289;
|
33
|
+
|
34
|
+
SORT_RELEVANCE = 'relevance';
|
35
|
+
SORT_UPDATED = 'updated_date';
|
36
|
+
SORT_CREATED = 'created_date';
|
37
|
+
SORT_MOST_VIEWED = 'most_viewed';
|
38
|
+
SORT_PRICE = 'price';
|
39
|
+
|
40
|
+
TYPE_PRODUCTS = 'products';
|
41
|
+
TYPE_CATEGORIES = 'categories';
|
42
|
+
|
43
|
+
API_ENVIRONMENT_STAGE = 'stage';
|
44
|
+
API_ENVIRONMENT_SANDBOX = 'sandbox';
|
45
|
+
API_ENVIRONMENT_LIVE = 'live';
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AboutYou
|
2
|
+
module SDK
|
3
|
+
module Criteria
|
4
|
+
class ProductFields
|
5
|
+
###
|
6
|
+
# id and name is set per default
|
7
|
+
###
|
8
|
+
IS_ACTIVE = "active"
|
9
|
+
BRAND = "brand_id"
|
10
|
+
DESCRIPTION_LONG = "description_long"
|
11
|
+
DESCRIPTION_SHORT = "description_short"
|
12
|
+
DEFAULT_VARIANT = "default_variant"
|
13
|
+
VARIANTS = "variants"
|
14
|
+
MIN_PRICE = "min_price"
|
15
|
+
MAX_PRICE = "max_price"
|
16
|
+
IS_SALE = "sale"
|
17
|
+
DEFAULT_IMAGE = "default_image"
|
18
|
+
ATTRIBUTES_MERGED = "attributes_merged"
|
19
|
+
CATEGORIES = "categories"
|
20
|
+
INACTIVE_VARIANTS = "inactive_variants"
|
21
|
+
MAX_SAVINGS = "max_savings"
|
22
|
+
MAX_SAVINGS_PERCENTAGE = "max_savings_percentage"
|
23
|
+
tags = "tags"
|
24
|
+
|
25
|
+
def self.filterFields(fields)
|
26
|
+
fields = fields.uniq
|
27
|
+
|
28
|
+
# this simplifies parsing on (pre)fetching facets
|
29
|
+
if (
|
30
|
+
fields.include? ATTRIBUTES_MERGED && (
|
31
|
+
fields.include?(BRAND) ||
|
32
|
+
fields.include?(VARIANTS) ||
|
33
|
+
fields.include?(DEFAULT_VARIANT)
|
34
|
+
)
|
35
|
+
)
|
36
|
+
fields.push(ATTRIBUTES_MERGED)
|
37
|
+
end
|
38
|
+
|
39
|
+
return fields;
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.requiresFacets(fields)
|
43
|
+
requiredFacetFields = [BRAND,VARIANTS,DEFAULT_VARIANT,ATTRIBUTES_MERGED] & fields
|
44
|
+
return (requiredFacetFields.count > 0);
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.requiresCategories(fields)
|
48
|
+
|
49
|
+
return fields.include?(CATEGORIES)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,436 @@
|
|
1
|
+
module AboutYou
|
2
|
+
module SDK
|
3
|
+
module Criteria
|
4
|
+
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
|
35
|
+
end
|
36
|
+
|
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);
|
104
|
+
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
|
116
|
+
end
|
117
|
+
categoryIds = categoryIds.uniq
|
118
|
+
|
119
|
+
return self.filterBy(FILTER_CATEGORY_IDS, categoryIds);
|
120
|
+
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
|
+
|
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']
|
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;
|
306
|
+
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);
|
317
|
+
end
|
318
|
+
|
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;
|
330
|
+
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
|
340
|
+
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;
|
356
|
+
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;
|
376
|
+
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;
|
388
|
+
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;
|
400
|
+
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
|
+
|
407
|
+
return (productCategories || categoryFacets)
|
408
|
+
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)
|
415
|
+
end
|
416
|
+
|
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
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|