aboutyou-sdk 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/aboutyou-sdk.rb +443 -489
- data/lib/aboutyou-sdk/Client.rb +86 -111
- data/lib/aboutyou-sdk/Constants.rb +34 -34
- data/lib/aboutyou-sdk/Criteria/ProductSearchCriteria.rb +1 -1
- data/lib/aboutyou-sdk/Query.rb +219 -218
- data/lib/aboutyou-sdk/QueryBuilder.rb +414 -432
- data/tests/testAutocomplete.rb +0 -1
- data/tests/testFacets.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTM0MmUzNTAxZDAzY2NiMmVhNzg4YjY1MmYzYjBhZmMzNjg3ODFlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTg2NzY5NzQ3YWQzM2Q4ZDI5MTRkOGJkOGYyZmFkYTdhMWZkMzU1NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDM1NTc0ZjFmZmVlYjI0YWY0YTI1MTk2MGYyNTkwMGNiOWZmNDI1NjA0MzUx
|
10
|
+
ZWQzMGNlNjVlMzI0YjY3MTZkYTIyMmI2NjlmOGZiMzVmZjY3ZTk3NmU1YTM5
|
11
|
+
ZTk2NmM1MTM5NmRkOTkzYzk5ZWI4YzhkOGYwNzNmMGEzNzczNGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmE2MTI3OThmMjRlODhhMTNlNGQ1M2ExOTJmYzFhOTNjNjU0YWMzNWZmMDI4
|
14
|
+
OWEyODkyNWIyNzMwZTU2NjA2M2MwZDRmYTA4Y2MxOGNjY2JlYzM1ZjAyNjJl
|
15
|
+
ZWVhYWUyMWQ0ZGMxODIxYmU5ZmM5MmQyMzVkMGQxMGYyZjM5YmI=
|
data/lib/aboutyou-sdk.rb
CHANGED
@@ -6,539 +6,493 @@ require_rel "aboutyou-sdk"
|
|
6
6
|
|
7
7
|
###
|
8
8
|
# Provides access to the Collins Frontend Platform.
|
9
|
-
# This class is abstract because it's not meant to be instanciated.
|
10
9
|
# All the public methods cover a single API query.
|
11
10
|
#
|
12
11
|
# @author Collins GmbH & Co KG
|
13
12
|
###
|
14
13
|
class AY
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
self.sessionId = sessionId
|
52
|
-
self.appId = appId
|
53
|
-
self.appPassword = appPassword
|
54
|
-
self.aboutYouClient = aboutYouClient
|
55
|
-
self.apiEndPoint = apiEndPoint
|
14
|
+
IMAGE_URL_STAGE = 'http://mndb.staging.aboutyou.de/mmdb/file'
|
15
|
+
IMAGE_URL_SANDBOX = 'http://mndb.sandbox.aboutyou.de/mmdb/file'
|
16
|
+
IMAGE_URL_LIVE = 'http://cdn.aboutyou.de/file'
|
17
|
+
|
18
|
+
attr_accessor :aboutYouClient
|
19
|
+
attr_accessor :appId
|
20
|
+
attr_accessor :appPassword
|
21
|
+
attr_accessor :apiEndPoint
|
22
|
+
attr_accessor :environment
|
23
|
+
attr_accessor :logger
|
24
|
+
attr_accessor :modelFactoryInstance
|
25
|
+
attr_accessor :baseImageUrl
|
26
|
+
attr_accessor :sessionId
|
27
|
+
|
28
|
+
###
|
29
|
+
# @param apiEndPoint=>live = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE
|
30
|
+
# @param apiEndPoint=>staging = AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
31
|
+
# @param resultFactory if null it will use the DefaultModelFactory with the DefaultFacetManager
|
32
|
+
###
|
33
|
+
def initialize(appId,appPassword,sessionId = 'SESSION_ID', apiEndPoint = AboutYou::SDK::Constants::API_ENVIRONMENT_LIVE, resultFactory = nil, logger = nil,facetManagerCache = nil)
|
34
|
+
|
35
|
+
self.sessionId = sessionId
|
36
|
+
self.appId = appId
|
37
|
+
self.appPassword = appPassword
|
38
|
+
self.aboutYouClient = AboutYou::SDK::Client.new(appId, appPassword, apiEndPoint, logger)
|
39
|
+
|
40
|
+
if apiEndPoint == AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
41
|
+
self.baseImageUrl=(IMAGE_URL_STAGE)
|
42
|
+
self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
43
|
+
elsif apiEndPoint == AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
|
44
|
+
self.baseImageUrl=(IMAGE_URL_SANDBOX)
|
45
|
+
self.environment = AboutYou::SDK::Constants::API_ENVIRONMENT_SANDBOX
|
46
|
+
else
|
47
|
+
self.baseImageUrl=(IMAGE_URL_LIVE)
|
56
48
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
basket = AboutYou::SDK::Model::Basket.new()
|
86
|
-
|
87
|
-
amount.times do
|
88
|
-
item = AboutYou::SDK::Model::Basket::BasketItem.new(generateBasketItemId(), variantId)
|
89
|
-
basket.updateItem(item)
|
90
|
-
end
|
91
|
-
|
92
|
-
updateBasket(sessionId, basket);
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
###
|
53
|
+
# Adds a single item into the basket.
|
54
|
+
# You can specify an amount. Please mind, that an amount > 1 will result in #amount basket positions.
|
55
|
+
# So if you read out the basket again later, it's your job to merge the positions again.
|
56
|
+
#
|
57
|
+
# It is highly recommend to use the basket update method, to manage your items.
|
58
|
+
#
|
59
|
+
# @param string $sessionId
|
60
|
+
# @param integer $variantId
|
61
|
+
# @param integer $amount
|
62
|
+
#
|
63
|
+
# @return Basket
|
64
|
+
#
|
65
|
+
# @throws \InvalidArgumentException
|
66
|
+
##
|
67
|
+
def addItemToBasket(sessionId, variantId, amount = 1)
|
68
|
+
|
69
|
+
basket = AboutYou::SDK::Model::Basket.new
|
70
|
+
|
71
|
+
unless variantId.is_a? Long
|
72
|
+
if variantId.is_a? String && variantId[/\d/]
|
73
|
+
variantId = Integer(variantId)
|
74
|
+
else
|
75
|
+
raise 'the variant id must be an integer or string with digits'
|
76
|
+
end
|
93
77
|
end
|
94
78
|
|
95
|
-
|
96
|
-
def generateBasketItemId()
|
97
|
-
|
98
|
-
'i_' + SecureRandom.uuid
|
99
79
|
|
80
|
+
amount.times do
|
81
|
+
basket.updateItem(AboutYou::SDK::Model::Basket::BasketItem.new(generateBasketItemId, variantId))
|
100
82
|
end
|
101
83
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
84
|
+
updateBasket(sessionId, basket)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def generateBasketItemId
|
89
|
+
|
90
|
+
'i_' + SecureRandom.uuid
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
###
|
95
|
+
# Remove basket item.
|
96
|
+
#
|
97
|
+
# @param string $sessionId Free to choose ID of the current website visitor.
|
98
|
+
# @param string[] $itemIds array of basket item ids to delete, this can be sets or single items
|
99
|
+
#
|
100
|
+
# @return \Collins\ShopApi\Model\Basket
|
101
|
+
###
|
102
|
+
def removeItemsFromBasket(sessionId, itemIds)
|
103
|
+
|
104
|
+
basket = AboutYou::SDK::Model::Basket.new
|
105
|
+
basket.deleteItems(itemIds)
|
106
|
+
|
107
|
+
updateBasket(sessionId, basket)
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
###
|
112
|
+
# @param string $sessionId
|
113
|
+
# @param Basket $basket
|
114
|
+
#
|
115
|
+
# @return \Collins\ShopApi\Model\Basket
|
116
|
+
###
|
117
|
+
def updateBasket(sessionId, basket)
|
118
|
+
|
119
|
+
query.updateBasket(sessionId, basket).executeSingle
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
###
|
124
|
+
# @param string $sessionId the session id
|
125
|
+
# @param string $successUrl callback URL if the order was OK
|
126
|
+
# @param string $cancelUrl callback URL if the order was canceled [optional]
|
127
|
+
# @param string $errorUrl callback URL if the order had any exceptions [optional]
|
128
|
+
#
|
129
|
+
# @return \Collins\ShopApi\Model\InitiateOrder
|
130
|
+
###
|
131
|
+
def initiateOrder(sessionId,successUrl,cancelUrl = nil,errorUrl = nil)
|
132
|
+
|
133
|
+
query.initiateOrder(sessionId, successUrl, cancelUrl, errorUrl).executeSingle
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
###
|
138
|
+
# Returns the result of an auto completion API request.
|
139
|
+
# Auto completion searches for products and categories by
|
140
|
+
# a given prefix ($searchword).
|
141
|
+
#
|
142
|
+
# @param string $searchword The prefix search word to search for.
|
143
|
+
# @param int $limit Maximum number of results.
|
144
|
+
# @param array $types Array of types to search for (Constants::TYPE_...).
|
145
|
+
#
|
146
|
+
# @return \Collins\ShopApi\Model\Autocomplete
|
147
|
+
###
|
148
|
+
def fetchAutocomplete(searchword, limit = 50, types = [AboutYou::SDK::Constants::TYPE_PRODUCTS, AboutYou::SDK::Constants::TYPE_CATEGORIES])
|
149
|
+
|
150
|
+
query.fetchAutocomplete(searchword, limit, types).executeSingle
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
###
|
155
|
+
# Fetch the basket of the given sessionId.
|
156
|
+
#
|
157
|
+
# @param string $sessionId Free to choose ID of the current website visitor.
|
158
|
+
#
|
159
|
+
# @return \Collins\ShopApi\Model\Basket
|
160
|
+
#
|
161
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
162
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
163
|
+
###
|
164
|
+
def fetchBasket(sessionId)
|
165
|
+
|
166
|
+
query.fetchBasket(sessionId).executeSingle
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
###
|
171
|
+
# Returns the result of a category search API request.
|
172
|
+
# By passing one or several category ids it will return
|
173
|
+
# a result of the categories data.
|
174
|
+
#
|
175
|
+
# @param mixed $ids either a single category ID as integer or an array of IDs
|
176
|
+
#
|
177
|
+
# @return \Collins\ShopApi\Model\CategoriesResult
|
178
|
+
###
|
179
|
+
def fetchCategoriesByIds(ids = nil)
|
180
|
+
# we allow to pass a single ID instead of an array
|
181
|
+
|
182
|
+
if ids
|
183
|
+
ids = Array(ids)
|
117
184
|
end
|
118
185
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
186
|
+
categoryManager = self.categoryManager
|
187
|
+
return AboutYou::SDK::Model::CategoriesResult.new(categoryManager, ids)
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
###
|
192
|
+
# @param int $maxDepth -1 <= $maxDepth <= 10
|
193
|
+
#
|
194
|
+
# @return CategoryTree
|
195
|
+
#
|
196
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
197
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
198
|
+
###
|
199
|
+
def fetchCategoryTree
|
200
|
+
|
201
|
+
AboutYou::SDK::Model::CategoryTree.new(self.categoryManager)
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
###
|
206
|
+
# The Categories will be fetch automatically, if required by any other fetch method
|
207
|
+
#
|
208
|
+
# For Example
|
209
|
+
# $productsResult = $api->fetchProductsByIds([12345], ['categories']);
|
210
|
+
# will fetch the categories with the same request.
|
211
|
+
# $rootCategories = $api->getCategoryManager()->getCategoryTree();
|
212
|
+
# will give you all categories for your Menu without an other request
|
213
|
+
#
|
214
|
+
# @param bool $fetchIfEmpty
|
215
|
+
#
|
216
|
+
# @return CategoryManagerInterface
|
217
|
+
###
|
218
|
+
def categoryManager(fetchIfEmpty = true)
|
219
|
+
|
220
|
+
categoryManager = self.modelFactory.categoryManager
|
221
|
+
|
222
|
+
if fetchIfEmpty && categoryManager.isEmpty
|
223
|
+
query.requireCategoryTree.executeSingle
|
131
224
|
end
|
132
225
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
#
|
155
|
-
# @param string $searchword The prefix search word to search for.
|
156
|
-
# @param int $limit Maximum number of results.
|
157
|
-
# @param array $types Array of types to search for (Constants::TYPE_...).
|
158
|
-
#
|
159
|
-
# @return \Collins\ShopApi\Model\Autocomplete
|
160
|
-
###
|
161
|
-
def fetchAutocomplete(searchword, limit = 50, types = [AboutYou::SDK::Constants::TYPE_PRODUCTS, AboutYou::SDK::Constants::TYPE_CATEGORIES])
|
162
|
-
|
163
|
-
query = query().fetchAutocomplete(searchword, limit, types)
|
164
|
-
|
165
|
-
query.executeSingle()
|
226
|
+
categoryManager
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
###
|
231
|
+
# @param integer[] $ids
|
232
|
+
# @param string[] $fields
|
233
|
+
#
|
234
|
+
# @return ProductsResult
|
235
|
+
#
|
236
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
237
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
238
|
+
###
|
239
|
+
def fetchProductsByIds(ids , fields = [])
|
240
|
+
# we allow to pass a single ID instead of an array
|
241
|
+
ids = Array(ids)
|
242
|
+
result = query.fetchProductsByIds(ids, fields).executeSingle
|
243
|
+
productsNotFound = result.getProductsNotFound
|
244
|
+
|
245
|
+
if !productsNotFound.empty? && self.logger
|
246
|
+
self.logger.warning('products not found: appid=' + self.appId + ' product ids=[' + productsNotFound.join(',') + ']')
|
166
247
|
end
|
167
248
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
249
|
+
result
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
###
|
254
|
+
# @param integer[] $ids
|
255
|
+
#
|
256
|
+
# @return ShopApi\Model\VariantsResult
|
257
|
+
#
|
258
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
259
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
260
|
+
###
|
261
|
+
def fetchVariantsByIds(ids)
|
262
|
+
# we allow to pass a single ID instead of an array
|
263
|
+
|
264
|
+
ids = Array(ids)
|
265
|
+
result = query.fetchLiveVariantByIds(ids).executeSingle
|
266
|
+
variantsNotFound = result.variantsNotFound
|
267
|
+
|
268
|
+
if result.hasVariantsNotFound && self.logger
|
269
|
+
self.logger.warning('variants or products for variants not found: appid='+self.appId+' variant ids=['+variantsNotFound.join(',')+']')
|
270
|
+
end
|
271
|
+
|
272
|
+
result
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
###
|
277
|
+
# @param string[] $eans
|
278
|
+
# @param string[] $fields
|
279
|
+
#
|
280
|
+
# @return ProductsEansResult
|
281
|
+
#
|
282
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
283
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
284
|
+
###
|
285
|
+
def fetchProductsByEans(eans,fields = [])
|
286
|
+
# we allow to pass a single ID instead of an array
|
287
|
+
|
288
|
+
eans = Array(eans)
|
289
|
+
|
290
|
+
query.fetchProductsByEans(eans, fields).executeSingle
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
###
|
295
|
+
# @param ProductSearchCriteria $criteria
|
296
|
+
#
|
297
|
+
# @return ProductSearchResult
|
298
|
+
#
|
299
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
300
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
301
|
+
###
|
302
|
+
def fetchProductSearch(criteria)
|
303
|
+
|
304
|
+
query.fetchProductSearch(criteria).executeSingle
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
###
|
309
|
+
# Fetch the facets of the given groupIds.
|
310
|
+
#
|
311
|
+
# @param array $groupIds The group ids.
|
312
|
+
#
|
313
|
+
# @return \Collins\ShopApi\Model\Facet[] With facet id as key.
|
314
|
+
#
|
315
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
316
|
+
#@throws ShopApi\Exception\UnexpectedResultException
|
317
|
+
###
|
318
|
+
def fetchFacets(groupIds=[])
|
319
|
+
|
320
|
+
query.fetchFacets(groupIds).executeSingle
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
def fetchFacetTypes
|
325
|
+
|
326
|
+
query.fetchFacetTypes.executeSingle
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
###
|
331
|
+
# @param string|integer $orderId the order id
|
332
|
+
#
|
333
|
+
# @return \Collins\ShopApi\Model\Order the order
|
334
|
+
###
|
335
|
+
def fetchOrder(orderId)
|
336
|
+
|
337
|
+
query.fetchOrder(orderId).executeSingle
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
###
|
342
|
+
# Fetch single facets by id and group id
|
343
|
+
# For example:
|
344
|
+
# $shopApi->fetchFacet([
|
345
|
+
# ["id" => 123, "group_id" => 0 ],
|
346
|
+
# ["id" => 456, "group_id" => 0 ]
|
347
|
+
# ])
|
348
|
+
#
|
349
|
+
# @param array $params Array of (id, group_id) pairs
|
350
|
+
#
|
351
|
+
# @return \Collins\ShopApi\Model\Facet[] With facet id as key.
|
352
|
+
#
|
353
|
+
# @throws ShopApi\Exception\MalformedJsonException
|
354
|
+
# @throws ShopApi\Exception\UnexpectedResultException
|
355
|
+
###
|
356
|
+
def fetchFacet(params)
|
357
|
+
|
358
|
+
query.fetchFacet(params).executeSingle
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
###
|
363
|
+
# Returns the result of a suggest API request.
|
364
|
+
# Suggestions are words that are often searched together
|
365
|
+
# with the searchword you pass (e.g. "stretch" for "jeans").
|
366
|
+
#
|
367
|
+
# @param string $searchword The search string to search for.
|
368
|
+
#
|
369
|
+
# @return array
|
370
|
+
###
|
371
|
+
def fetchSuggest(searchword)
|
372
|
+
|
373
|
+
query.fetchSuggest(searchword).executeSingle
|
374
|
+
end
|
375
|
+
|
376
|
+
|
377
|
+
###
|
378
|
+
# Returns the list of child apps
|
379
|
+
#
|
380
|
+
# @return array
|
381
|
+
###
|
382
|
+
def fetchChildApps
|
182
383
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
###
|
188
|
-
# Returns the result of a category search API request.
|
189
|
-
# By passing one or several category ids it will return
|
190
|
-
# a result of the categories data.
|
191
|
-
#
|
192
|
-
# @param mixed $ids either a single category ID as integer or an array of IDs
|
193
|
-
#
|
194
|
-
# @return \Collins\ShopApi\Model\CategoriesResult
|
195
|
-
###
|
196
|
-
def fetchCategoriesByIds(ids = nil)
|
197
|
-
# we allow to pass a single ID instead of an array
|
198
|
-
|
199
|
-
if (ids != nil)
|
200
|
-
ids = Array(ids)
|
201
|
-
end
|
384
|
+
query.fetchChildApps.executeSingle
|
385
|
+
end
|
202
386
|
|
203
|
-
categoryManager = self.categoryManager
|
204
|
-
return AboutYou::SDK::Model::CategoriesResult.new(categoryManager, ids)
|
205
|
-
end
|
206
|
-
|
207
387
|
|
208
|
-
|
209
|
-
# @param int $maxDepth -1 <= $maxDepth <= 10
|
210
|
-
#
|
211
|
-
# @return CategoryTree
|
212
|
-
#
|
213
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
214
|
-
# @throws ShopApi\Exception\UnexpectedResultException
|
215
|
-
###
|
216
|
-
def fetchCategoryTree()
|
217
|
-
|
218
|
-
return AboutYou::SDK::Model::CategoryTree.new(self.categoryManager())
|
219
|
-
end
|
220
|
-
|
221
|
-
###
|
222
|
-
# The Categories will be fetch automatically, if required by any other fetch method
|
223
|
-
#
|
224
|
-
# For Example
|
225
|
-
# $productsResult = $api->fetchProductsByIds([12345], ['categories']);
|
226
|
-
# will fetch the categories with the same request.
|
227
|
-
# $rootCategories = $api->getCategoryManager()->getCategoryTree();
|
228
|
-
# will give you all categories for your Menu without an other request
|
229
|
-
#
|
230
|
-
# @param bool $fetchIfEmpty
|
231
|
-
#
|
232
|
-
# @return CategoryManagerInterface
|
233
|
-
###
|
234
|
-
def categoryManager(fetchIfEmpty = true)
|
235
|
-
|
236
|
-
categoryManager = self.modelFactory.categoryManager();
|
388
|
+
def query
|
237
389
|
|
238
|
-
|
239
|
-
|
240
|
-
end
|
390
|
+
AboutYou::SDK::Query.new(self.aboutYouClient, modelFactory)
|
391
|
+
end
|
241
392
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
# @param integer[] $ids
|
248
|
-
# @param string[] $fields
|
249
|
-
#
|
250
|
-
# @return ProductsResult
|
251
|
-
#
|
252
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
253
|
-
# @throws ShopApi\Exception\UnexpectedResultException
|
254
|
-
###
|
255
|
-
def fetchProductsByIds(ids , fields = Array(nil))
|
256
|
-
# we allow to pass a single ID instead of an array
|
257
|
-
|
258
|
-
ids = Array(ids)
|
259
|
-
query = query().fetchProductsByIds(ids, fields)
|
260
|
-
result = query.executeSingle()
|
261
|
-
|
262
|
-
productsNotFound = result.getProductsNotFound()
|
263
|
-
if (!productsNotFound.empty? && self.logger)
|
264
|
-
self.logger.warning('products not found: appid=' + self.appId + ' product ids=[' + productsNotFound.join(',') + ']')
|
265
|
-
end
|
266
|
-
|
267
|
-
return result
|
393
|
+
|
394
|
+
def modelFactory
|
395
|
+
|
396
|
+
unless self.modelFactoryInstance
|
397
|
+
self.initDefaultFactory
|
268
398
|
end
|
269
|
-
|
270
399
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
query = query().fetchLiveVariantByIds(ids)
|
284
|
-
|
285
|
-
result = query.executeSingle()
|
286
|
-
|
287
|
-
variantsNotFound = result.variantsNotFound()
|
288
|
-
if (result.hasVariantsNotFound() && self.logger)
|
289
|
-
self.logger.warning('variants or products for variants not found: appid='+self.appId+' variant ids=['+variantsNotFound.join(',')+']')
|
290
|
-
end
|
291
|
-
|
292
|
-
return result
|
293
|
-
end
|
294
|
-
|
295
|
-
|
296
|
-
###
|
297
|
-
# @param string[] $eans
|
298
|
-
# @param string[] $fields
|
299
|
-
#
|
300
|
-
# @return ProductsEansResult
|
301
|
-
#
|
302
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
303
|
-
# @throws ShopApi\Exception\UnexpectedResultException
|
304
|
-
###
|
305
|
-
def fetchProductsByEans(eans,fields = Array())
|
306
|
-
# we allow to pass a single ID instead of an array
|
307
|
-
|
308
|
-
eans = Array(eans)
|
309
|
-
|
310
|
-
query = query().fetchProductsByEans(eans, fields)
|
311
|
-
|
312
|
-
query.executeSingle()
|
400
|
+
self.modelFactoryInstance
|
401
|
+
end
|
402
|
+
|
403
|
+
|
404
|
+
###
|
405
|
+
# @param string|nil $sessionId
|
406
|
+
#
|
407
|
+
# @return ProductSearchCriteria
|
408
|
+
###
|
409
|
+
def productSearchCriteria(sessionId=nil)
|
410
|
+
unless sessionId
|
411
|
+
sessionId = self.sessionId
|
313
412
|
end
|
314
413
|
|
315
|
-
|
316
|
-
|
317
|
-
# @param ProductSearchCriteria $criteria
|
318
|
-
#
|
319
|
-
# @return ProductSearchResult
|
320
|
-
#
|
321
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
322
|
-
# @throws ShopApi\Exception\UnexpectedResultException
|
323
|
-
###
|
324
|
-
def fetchProductSearch(criteria)
|
325
|
-
|
326
|
-
query = query().fetchProductSearch(criteria)
|
327
|
-
|
328
|
-
query.executeSingle()
|
329
|
-
end
|
414
|
+
AboutYou::SDK::Criteria::ProductSearchCriteria.new(self.sessionId)
|
415
|
+
end
|
330
416
|
|
331
|
-
|
332
|
-
###
|
333
|
-
# Fetch the facets of the given groupIds.
|
334
|
-
#
|
335
|
-
# @param array $groupIds The group ids.
|
336
|
-
#
|
337
|
-
# @return \Collins\ShopApi\Model\Facet[] With facet id as key.
|
338
|
-
#
|
339
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
340
|
-
#@throws ShopApi\Exception\UnexpectedResultException
|
341
|
-
###
|
342
|
-
def fetchFacets(groupIds=Array(nil))
|
343
|
-
|
344
|
-
query = query().fetchFacets(groupIds)
|
345
|
-
|
346
|
-
query.executeSingle()
|
347
|
-
end
|
348
417
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
418
|
+
###
|
419
|
+
# Returns the URL to the Collins JavaScript file for helper functions
|
420
|
+
# to add product variants into the basket of Mary & Paul or auto-resizing
|
421
|
+
# the Iframe. This URL may be changed in future, so please use this method instead
|
422
|
+
# of hardcoding the URL into your HTML template.
|
423
|
+
#
|
424
|
+
# @return string URL to the JavaScript file
|
425
|
+
###
|
426
|
+
def javaScriptURL
|
356
427
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
# @return \Collins\ShopApi\Model\Order the order
|
362
|
-
###
|
363
|
-
def fetchOrder(orderId)
|
364
|
-
|
365
|
-
query = query().fetchOrder(orderId)
|
366
|
-
|
367
|
-
query.executeSingle()
|
368
|
-
end
|
369
|
-
|
370
|
-
|
371
|
-
###
|
372
|
-
# Fetch single facets by id and group id
|
373
|
-
# For example:
|
374
|
-
# $shopApi->fetchFacet([
|
375
|
-
# ["id" => 123, "group_id" => 0 ],
|
376
|
-
# ["id" => 456, "group_id" => 0 ]
|
377
|
-
# ])
|
378
|
-
#
|
379
|
-
# @param array $params Array of (id, group_id) pairs
|
380
|
-
#
|
381
|
-
# @return \Collins\ShopApi\Model\Facet[] With facet id as key.
|
382
|
-
#
|
383
|
-
# @throws ShopApi\Exception\MalformedJsonException
|
384
|
-
# @throws ShopApi\Exception\UnexpectedResultException
|
385
|
-
###
|
386
|
-
def fetchFacet(params)
|
387
|
-
|
388
|
-
query = query().fetchFacet(params)
|
389
|
-
|
390
|
-
query.executeSingle()
|
428
|
+
if self.environment === AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE
|
429
|
+
'//devcenter-staging-www1.pub.collins.kg:81/appjs/'+String(self.appId)+'.js'
|
430
|
+
else
|
431
|
+
'//developer.aboutyou.de/appjs/'+String(self.appId)+'.js'
|
391
432
|
end
|
433
|
+
end
|
392
434
|
|
393
|
-
|
394
|
-
###
|
395
|
-
# Returns the result of a suggest API request.
|
396
|
-
# Suggestions are words that are often searched together
|
397
|
-
# with the searchword you pass (e.g. "stretch" for "jeans").
|
398
|
-
#
|
399
|
-
# @param string $searchword The search string to search for.
|
400
|
-
#
|
401
|
-
# @return array
|
402
|
-
###
|
403
|
-
def fetchSuggest(searchword)
|
404
|
-
|
405
|
-
query = query().fetchSuggest(searchword)
|
406
|
-
|
407
|
-
query.executeSingle()
|
408
|
-
end
|
409
435
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
def fetchChildApps()
|
417
|
-
|
418
|
-
query = query().fetchChildApps()
|
436
|
+
###
|
437
|
+
# Returns a HTML script tag that loads the Collins JavaScript fie.
|
438
|
+
#
|
439
|
+
# @return string HTML script tag
|
440
|
+
###
|
441
|
+
def javaScriptTag
|
419
442
|
|
420
|
-
|
421
|
-
|
443
|
+
'<script type="text/javascript" src="' + self.javaScriptURL + '"></script>'
|
444
|
+
end
|
422
445
|
|
423
|
-
|
424
|
-
def query()
|
425
|
-
|
426
|
-
AboutYou::SDK::Query.new(self.aboutYouClient, modelFactory())
|
427
|
-
end
|
428
446
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
# $closure = $this->modelFactoryInstance;
|
435
|
-
# $closure($this);
|
436
|
-
end
|
437
|
-
|
438
|
-
return self.modelFactoryInstance;
|
439
|
-
end
|
440
|
-
|
441
|
-
###
|
442
|
-
# @param string|nil $sessionId
|
443
|
-
#
|
444
|
-
# @return ProductSearchCriteria
|
445
|
-
###
|
446
|
-
def productSearchCriteria(sessionId=nil)
|
447
|
-
if !sessionId
|
448
|
-
sessionId = self.sessionId
|
449
|
-
end
|
450
|
-
AboutYou::SDK::Criteria::ProductSearchCriteria.new(self.sessionId)
|
451
|
-
end
|
447
|
+
###
|
448
|
+
# @param string $appId the app id for client authentication
|
449
|
+
# @param string $appPassword the app password/token for client authentication.
|
450
|
+
###
|
451
|
+
def appCredentials=(appId, appPassword)
|
452
452
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
# of hardcoding the URL into your HTML template.
|
459
|
-
#
|
460
|
-
# @return string URL to the JavaScript file
|
461
|
-
###
|
462
|
-
def javaScriptURL()
|
463
|
-
|
464
|
-
if (self.environment === AboutYou::SDK::Constants::API_ENVIRONMENT_STAGE)
|
465
|
-
'//devcenter-staging-www1.pub.collins.kg:81/appjs/'+String(self.appId)+'.js'
|
466
|
-
else
|
467
|
-
'//developer.aboutyou.de/appjs/'+String(self.appId)+'.js'
|
468
|
-
end
|
453
|
+
self.appId = appId
|
454
|
+
self.appPassword = appPassword
|
455
|
+
self.aboutYouClient.appId= appId
|
456
|
+
self.aboutYouClient.appPassword = appPassword
|
457
|
+
end
|
469
458
|
|
470
|
-
end
|
471
459
|
|
460
|
+
###
|
461
|
+
# @param string $apiEndPoint the endpoint can be the string 'stage' or 'live',
|
462
|
+
# then the default endpoints will be used or
|
463
|
+
# an absolute url
|
464
|
+
###
|
465
|
+
def apiEndpoint=(apiEndPoint)
|
472
466
|
|
473
|
-
|
474
|
-
|
475
|
-
#
|
476
|
-
# @return string HTML script tag
|
477
|
-
###
|
478
|
-
def javaScriptTag()
|
479
|
-
|
480
|
-
'<script type="text/javascript" src="' + self.javaScriptURL() + '"></script>'
|
481
|
-
end
|
467
|
+
self.aboutYouClient.apiEndpoint=(apiEndPoint)
|
468
|
+
end
|
482
469
|
|
483
|
-
|
484
|
-
###
|
485
|
-
# @param string $appId the app id for client authentication
|
486
|
-
# @param string $appPassword the app password/token for client authentication.
|
487
|
-
###
|
488
|
-
def setAppCredentials(appId, appPassword)
|
489
|
-
|
490
|
-
self.appId = appId
|
491
|
-
self.appPassword = appPassword
|
492
|
-
self.aboutYouClient.setAppCredentials(appId, appPassword)
|
493
|
-
end
|
494
470
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
# an absolute url
|
500
|
-
###
|
501
|
-
def setApiEndpoint(apiEndPoint)
|
502
|
-
|
503
|
-
self.aboutYouClient.setApiEndpoint(apiEndPoint)
|
504
|
-
end
|
471
|
+
###
|
472
|
+
# @param null|false|string $baseImageUrl null will reset to the default url, false to get relative urls, otherwise the url prefix
|
473
|
+
###
|
474
|
+
def baseImageUrl=(baseImageUrl = nil)
|
505
475
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
def setLogTemplate(logTemplate)
|
513
|
-
|
514
|
-
self.aboutYouClient.setLogTemplate(logTemplate)
|
476
|
+
if !baseImageUrl
|
477
|
+
@baseImageUrl = IMAGE_URL_LIVE
|
478
|
+
elsif baseImageUrl.is_a? String
|
479
|
+
@baseImageUrl = baseImageUrl.gsub(/[#{'/'}]+$/,'')
|
480
|
+
else
|
481
|
+
@baseImageUrl = ''
|
515
482
|
end
|
516
|
-
|
517
|
-
|
518
|
-
###
|
519
|
-
# @param null|false|string $baseImageUrl null will reset to the default url, false to get relative urls, otherwise the url prefix
|
520
|
-
###
|
521
|
-
def setBaseImageUrl(baseImageUrl = nil)
|
522
|
-
|
523
|
-
if (baseImageUrl === nil)
|
524
|
-
self.baseImageUrl = IMAGE_URL_LIVE
|
525
|
-
elsif (baseImageUrl.is_a? String)
|
526
|
-
self.baseImageUrl = baseImageUrl.gsub(/[#{'/'}]+$/,'')
|
527
|
-
else
|
528
|
-
self.baseImageUrl = ''
|
529
|
-
end
|
530
|
-
|
531
|
-
self.modelFactory().baseImageUrl=(self.baseImageUrl);
|
532
|
-
end
|
533
|
-
|
534
|
-
def initDefaultFactory(cache = nil)
|
535
483
|
|
536
|
-
|
537
|
-
|
484
|
+
self.modelFactory.baseImageUrl=(self.baseImageUrl)
|
485
|
+
end
|
538
486
|
|
539
|
-
|
540
|
-
resultFactory.baseImageUrl=(self.baseImageUrl);
|
487
|
+
def initDefaultFactory(cache = nil)
|
541
488
|
|
542
|
-
|
543
|
-
|
489
|
+
resultFactory = AboutYou::SDK::Factory::DefaultModelFactory.new(self,
|
490
|
+
AboutYou::SDK::Model::FacetManager::DefaultFacetManager.new,
|
491
|
+
AboutYou::SDK::Model::CategoryManager::DefaultCategoryManager.new(cache, self.appId)
|
492
|
+
)
|
493
|
+
resultFactory.baseImageUrl=(self.baseImageUrl)
|
494
|
+
|
495
|
+
self.modelFactoryInstance=(resultFactory)
|
496
|
+
end
|
497
|
+
|
544
498
|
end
|