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