aboutyou-sdk 0.0.24 → 0.0.25
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/CacheProvider/Dalli.rb → AboutYou/CacheProvider/dalli.rb} +18 -19
- data/lib/{aboutyou-sdk/CacheProvider/Redis.rb → AboutYou/CacheProvider/redis.rb} +19 -20
- data/lib/{aboutyou-sdk/Criteria/ProductFields.rb → AboutYou/Criteria/product_fields.rb} +25 -27
- data/lib/{aboutyou-sdk/Criteria/ProductSearchCriteria.rb → AboutYou/Criteria/product_search_criteria.rb} +128 -123
- data/lib/{aboutyou-sdk/Factory/DefaultModelFactory.rb → AboutYou/Factory/default_model_factory.rb} +267 -224
- data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +57 -0
- data/lib/AboutYou/Model/Basket/basket_item.rb +95 -0
- data/lib/AboutYou/Model/Basket/basket_set.rb +199 -0
- data/lib/AboutYou/Model/Basket/basket_set_item.rb +54 -0
- data/lib/AboutYou/Model/Basket/basket_variant_item.rb +123 -0
- data/lib/{aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb → AboutYou/Model/CategoryManager/default_category_manager.rb} +80 -65
- data/lib/{aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb → AboutYou/Model/FacetManager/default_facet_manager.rb} +58 -50
- data/lib/{aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb → AboutYou/Model/ProductSearchResult/facet_count.rb} +2 -3
- data/lib/AboutYou/Model/ProductSearchResult/facet_counts.rb +67 -0
- data/lib/{aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb → AboutYou/Model/ProductSearchResult/price_range.rb} +17 -18
- data/lib/AboutYou/Model/ProductSearchResult/sale_counts.rb +79 -0
- data/lib/AboutYou/Model/ProductSearchResult/terms_count.rb +40 -0
- data/lib/{aboutyou-sdk/Model/AbstractModel.rb → AboutYou/Model/abstract_model.rb} +2 -3
- data/lib/{aboutyou-sdk/Model/App.rb → AboutYou/Model/app.rb} +15 -15
- data/lib/{aboutyou-sdk/Model/Autocomplete.rb → AboutYou/Model/autocomplete.rb} +25 -32
- data/lib/AboutYou/Model/basket.rb +235 -0
- data/lib/AboutYou/Model/categories_result.rb +24 -0
- data/lib/AboutYou/Model/category.rb +102 -0
- data/lib/AboutYou/Model/category_tree.rb +37 -0
- data/lib/AboutYou/Model/facet.rb +86 -0
- data/lib/AboutYou/Model/facet_group.rb +96 -0
- data/lib/AboutYou/Model/facet_group_set.rb +209 -0
- data/lib/AboutYou/Model/image.rb +102 -0
- data/lib/{aboutyou-sdk/Model/ImageSize.rb → AboutYou/Model/image_size.rb} +9 -5
- data/lib/AboutYou/Model/initiate_order.rb +53 -0
- data/lib/AboutYou/Model/order.rb +22 -0
- data/lib/AboutYou/Model/product.rb +353 -0
- data/lib/AboutYou/Model/product_search_result.rb +114 -0
- data/lib/AboutYou/Model/products_ean_result.rb +43 -0
- data/lib/AboutYou/Model/products_result.rb +56 -0
- data/lib/AboutYou/Model/result_error.rb +28 -0
- data/lib/AboutYou/Model/variant.rb +214 -0
- data/lib/AboutYou/Model/variants_result.rb +91 -0
- data/lib/AboutYou/client.rb +128 -0
- data/lib/{aboutyou-sdk/Constants.rb → AboutYou/constants.rb} +3 -5
- data/lib/AboutYou/query.rb +343 -0
- data/lib/AboutYou/query_builder.rb +530 -0
- data/lib/ay.rb +566 -0
- data/tests/Sinatra-test/Main.rb +3 -0
- data/tests/testAutocomplete.rb +5 -6
- data/tests/testCatFilter.rb +8 -9
- data/tests/testCatTree.rb +3 -3
- data/tests/testCategoryCaching.rb +4 -5
- data/tests/{testFacetCaching.rb → testDalliCache.rb} +4 -5
- data/tests/testFacetTypes.rb +5 -6
- data/tests/testFacets.rb +7 -8
- data/tests/testFetchFacet.rb +5 -6
- data/tests/testJavaScript.rb +3 -4
- data/tests/testProdCatLongestPath.rb +7 -8
- data/tests/testProductSearchResult.rb +6 -7
- data/tests/testProductsByEans.rb +6 -7
- data/tests/testProductsByIds.rb +6 -7
- data/tests/testRedisCache.rb +4 -5
- data/tests/testSuggest.rb +5 -6
- data/tests/testVariantsByIds.rb +7 -8
- metadata +46 -46
- data/lib/aboutyou-sdk.rb +0 -596
- data/lib/aboutyou-sdk/Client.rb +0 -134
- data/lib/aboutyou-sdk/Model/Basket.rb +0 -268
- data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +0 -76
- data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +0 -100
- data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +0 -192
- data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +0 -46
- data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +0 -137
- data/lib/aboutyou-sdk/Model/CategoriesResult.rb +0 -15
- data/lib/aboutyou-sdk/Model/Category.rb +0 -126
- data/lib/aboutyou-sdk/Model/CategoryTree.rb +0 -35
- data/lib/aboutyou-sdk/Model/Facet.rb +0 -105
- data/lib/aboutyou-sdk/Model/FacetGroup.rb +0 -110
- data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +0 -242
- data/lib/aboutyou-sdk/Model/Image.rb +0 -134
- data/lib/aboutyou-sdk/Model/InitiateOrder.rb +0 -50
- data/lib/aboutyou-sdk/Model/Order.rb +0 -17
- data/lib/aboutyou-sdk/Model/Product.rb +0 -335
- data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +0 -125
- data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +0 -59
- data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +0 -71
- data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +0 -36
- data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +0 -47
- data/lib/aboutyou-sdk/Model/ProductsResult.rb +0 -52
- data/lib/aboutyou-sdk/Model/ResultError.rb +0 -24
- data/lib/aboutyou-sdk/Model/Variant.rb +0 -255
- data/lib/aboutyou-sdk/Model/VariantsResult.rb +0 -102
- data/lib/aboutyou-sdk/Query.rb +0 -350
- data/lib/aboutyou-sdk/QueryBuilder.rb +0 -499
@@ -1,125 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
class ProductSearchResult
|
5
|
-
|
6
|
-
attr_accessor :products
|
7
|
-
attr_accessor :pageHash
|
8
|
-
attr_accessor :productCount
|
9
|
-
attr_accessor :saleCounts
|
10
|
-
attr_accessor :priceRanges
|
11
|
-
attr_accessor :facets
|
12
|
-
attr_accessor :categories
|
13
|
-
attr_accessor :rawFacets
|
14
|
-
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
|
18
|
-
self.products = Hash.new
|
19
|
-
end
|
20
|
-
|
21
|
-
###
|
22
|
-
# @param \stdClass $jsonObject
|
23
|
-
# @param ModelFactoryInterface $factory
|
24
|
-
#
|
25
|
-
# @return static
|
26
|
-
###
|
27
|
-
def self.createFromJson(jsonObject, factory)
|
28
|
-
productSearchResult = self.new
|
29
|
-
jsonObj = jsonObject
|
30
|
-
|
31
|
-
productSearchResult.pageHash = jsonObj["pageHash"];
|
32
|
-
productSearchResult.productCount = jsonObj["product_count"];
|
33
|
-
productSearchResult.rawFacets = jsonObj["facets"];
|
34
|
-
|
35
|
-
jsonObj["products"].each do |jsonProduct|
|
36
|
-
product = factory.createProduct(jsonProduct)
|
37
|
-
productSearchResult.products[product.id] = product
|
38
|
-
end
|
39
|
-
productSearchResult.parseFacets(jsonObj["facets"], factory);
|
40
|
-
#free memory
|
41
|
-
jsonObj["categories"] = nil
|
42
|
-
jsonObj["prices"] = nil
|
43
|
-
jsonObj["sale"] = nil
|
44
|
-
productSearchResult.facets= factory.createFacetsCounts(jsonObject)
|
45
|
-
|
46
|
-
return productSearchResult;
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def parseFacets(jsonObject, factory)
|
51
|
-
if (jsonObject["categories"])
|
52
|
-
self.categories = factory.createCategoriesFacets(jsonObject["categories"])
|
53
|
-
end
|
54
|
-
if (jsonObject["prices"])
|
55
|
-
self.priceRanges = factory.createPriceRanges(jsonObject["prices"]);
|
56
|
-
end
|
57
|
-
if (jsonObject["sale"])
|
58
|
-
self.saleCounts = factory.createSaleFacet(jsonObject["sale"]);
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
###
|
64
|
-
# Returns the min price in euro cent or null, if the price range was not requested/selected
|
65
|
-
#
|
66
|
-
# * @return integer|null
|
67
|
-
###
|
68
|
-
def minPrice()
|
69
|
-
|
70
|
-
if (self.priceRanges.empty?)
|
71
|
-
return nil;
|
72
|
-
end
|
73
|
-
|
74
|
-
self.priceRanges.each do |priceRange|
|
75
|
-
if (priceRange.productCount === 0)
|
76
|
-
next;
|
77
|
-
end
|
78
|
-
|
79
|
-
return priceRange.min;
|
80
|
-
end
|
81
|
-
|
82
|
-
return self.priceRanges[0].min
|
83
|
-
end
|
84
|
-
|
85
|
-
###
|
86
|
-
# Returns the max price in euro cent, if the price range was not requested/selected
|
87
|
-
#
|
88
|
-
# @return integer|null
|
89
|
-
###
|
90
|
-
def maxPrice()
|
91
|
-
|
92
|
-
if (self.priceRanges.empty?)
|
93
|
-
return nil;
|
94
|
-
end
|
95
|
-
|
96
|
-
maxPrice = 0;
|
97
|
-
self.priceRanges.reverse_each do |priceRange|
|
98
|
-
if (priceRange.productCount == 0)
|
99
|
-
next;
|
100
|
-
end
|
101
|
-
|
102
|
-
return priceRange.max();
|
103
|
-
end
|
104
|
-
|
105
|
-
return self.priceRanges[-1].max;
|
106
|
-
end
|
107
|
-
|
108
|
-
###
|
109
|
-
# @return Category[]
|
110
|
-
###
|
111
|
-
def categoryTree()
|
112
|
-
|
113
|
-
topLevelCategories = Array(nil);
|
114
|
-
self.categories.each do |category|
|
115
|
-
if (category.parent() == nil)
|
116
|
-
topLevelCategories.push(category);
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
return topLevelCategories;
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
###
|
5
|
-
# This class represents a FacetCounts model.
|
6
|
-
#
|
7
|
-
# author:: Collins GmbH & Co KG
|
8
|
-
###
|
9
|
-
class FacetCounts
|
10
|
-
# The groupId of the facetcounts
|
11
|
-
attr_accessor :groupId
|
12
|
-
# an array of facetcount objects
|
13
|
-
attr_accessor :facetCountList
|
14
|
-
# the cont of the products
|
15
|
-
attr_accessor :productCountTotal
|
16
|
-
# the count of the products without facets
|
17
|
-
attr_accessor :productCountWithoutAnyFacet
|
18
|
-
# the count of the procuts with other facets
|
19
|
-
attr_accessor :productCountWithOtherFacet
|
20
|
-
|
21
|
-
###
|
22
|
-
# the Constructor for the facetcounts class
|
23
|
-
#
|
24
|
-
# * *Args* :
|
25
|
-
# - +productCountTotal+ -> the total productcount
|
26
|
-
# - +productCountWithOtherFacet+ -> the productcount without any facets
|
27
|
-
# - +productCountWithoutAnyFacet+ -> the productcount with other facets
|
28
|
-
#
|
29
|
-
# * *Returns* :
|
30
|
-
# - Instance of AboutYou::SDK::Model::FacetCounts
|
31
|
-
###
|
32
|
-
def initialize(productCountTotal, productCountWithOtherFacet, productCountWithoutAnyFacet)
|
33
|
-
self.productCountTotal = productCountTotal
|
34
|
-
self.productCountWithOtherFacet = productCountWithOtherFacet
|
35
|
-
self.productCountWithoutAnyFacet = productCountWithoutAnyFacet
|
36
|
-
end
|
37
|
-
|
38
|
-
###
|
39
|
-
# This method is used for creating an instance of this class by a jsonObject.
|
40
|
-
#
|
41
|
-
# * *Args* :
|
42
|
-
# - +groupId+ -> the groupId of the facetcounts
|
43
|
-
# - +jsonObject+ -> the jsonObject received from the api
|
44
|
-
# - +facetCountList+ -> a list of facetcount objects
|
45
|
-
#
|
46
|
-
# * *Returns* :
|
47
|
-
# - Instance of AboutYou::SDK::Model::FacetCounts
|
48
|
-
###
|
49
|
-
def self.createFromJson(groupId, jsonObject, facetCountList)
|
50
|
-
facetCounts = self.new(jsonObject["total"], jsonObject["other"], jsonObject["missing"])
|
51
|
-
facetCounts.groupId = groupId
|
52
|
-
facetCounts.facetCountList = facetCountList
|
53
|
-
|
54
|
-
facetCounts
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
###
|
5
|
-
# This class represents a Sale Counts model.
|
6
|
-
#
|
7
|
-
# author:: Collins GmbH & Co KG
|
8
|
-
###
|
9
|
-
class SaleCounts
|
10
|
-
|
11
|
-
# count of products in sale
|
12
|
-
attr_accessor :productCountInSale
|
13
|
-
# count of prodocuts not in sale
|
14
|
-
attr_accessor :productCountNotInSale
|
15
|
-
# count of total products
|
16
|
-
attr_accessor :productCountTotal
|
17
|
-
# count of products without facet
|
18
|
-
attr_accessor :productCountWithoutAnyFacet
|
19
|
-
# count of products with other facets
|
20
|
-
attr_accessor :productCountWithOtherFacet
|
21
|
-
|
22
|
-
###
|
23
|
-
# the Constructor for the sale counts class
|
24
|
-
#
|
25
|
-
# * *Args* :
|
26
|
-
# - +productCountTotal+ -> the total productcount
|
27
|
-
# - +productCountWithOtherFacet+ -> the productcount without any facets
|
28
|
-
# - +productCountWithoutAnyFacet+ -> the productcount with other facets
|
29
|
-
#
|
30
|
-
# * *Returns* :
|
31
|
-
# - Instance of AboutYou::SDK::Model::SaleCounts
|
32
|
-
###
|
33
|
-
def initialize(productCountTotal, productCountWithOtherFacet, productCountWithoutAnyFacet)
|
34
|
-
self.productCountTotal = productCountTotal
|
35
|
-
self.productCountWithOtherFacet = productCountWithOtherFacet
|
36
|
-
self.productCountWithoutAnyFacet = productCountWithoutAnyFacet
|
37
|
-
end
|
38
|
-
|
39
|
-
###
|
40
|
-
# This method is used for creating an instance of this class by a jsonObject.
|
41
|
-
#
|
42
|
-
# * *Args* :
|
43
|
-
# - +jsonObject+ -> the jsonObject received from the api
|
44
|
-
#
|
45
|
-
# * *Returns* :
|
46
|
-
# - Instance of AboutYou::SDK::Model::SaleCounts
|
47
|
-
###
|
48
|
-
def self.createFromJson(jsonObject)
|
49
|
-
saleCounts = self.new(jsonObject["total"], jsonObject["other"], jsonObject["missing"])
|
50
|
-
saleCounts.parseTerms(jsonObject["terms"])
|
51
|
-
|
52
|
-
saleCounts
|
53
|
-
end
|
54
|
-
|
55
|
-
###
|
56
|
-
# This method is used for parsing the terms of the jsonObject
|
57
|
-
#
|
58
|
-
# * *Args* :
|
59
|
-
# - +jsonTerms+ -> the terms of the jsonObject received from the api
|
60
|
-
###
|
61
|
-
def parseTerms(jsonTerms)
|
62
|
-
jsonTerms.each do |term|
|
63
|
-
term["term"] == 0 ?
|
64
|
-
self.productCountNotInSale = term["count"] :
|
65
|
-
self.productCountInSale = term["count"]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
###
|
5
|
-
# This class represents a Terms Count model.
|
6
|
-
#
|
7
|
-
# author:: Collins GmbH & Co KG
|
8
|
-
###
|
9
|
-
class TermsCounts
|
10
|
-
# count of total products
|
11
|
-
attr_accessor :productCountTotal
|
12
|
-
# count of products without facet
|
13
|
-
attr_accessor :productCountWithOtherFacet
|
14
|
-
# count of products with other facets
|
15
|
-
attr_accessor :productCountWithoutAnyFacet
|
16
|
-
|
17
|
-
###
|
18
|
-
# the Constructor for the terms count class
|
19
|
-
#
|
20
|
-
# * *Args* :
|
21
|
-
# - +productCountTotal+ -> the total productcount
|
22
|
-
# - +productCountWithOtherFacet+ -> the productcount without any facets
|
23
|
-
# - +productCountWithoutAnyFacet+ -> the productcount with other facets
|
24
|
-
#
|
25
|
-
# * *Returns* :
|
26
|
-
# - Instance of AboutYou::SDK::Model::TermsCount
|
27
|
-
###
|
28
|
-
def initialize(productCountTotal, productCountWithOtherFacet, productCountWithoutAnyFacet)
|
29
|
-
self.productCountTotal = productCountTotal
|
30
|
-
self.productCountWithOtherFacet = productCountWithOtherFacet
|
31
|
-
self.productCountWithoutAnyFacet = productCountWithoutAnyFacet
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
class ProductsEansResult
|
5
|
-
|
6
|
-
# @var string[] #
|
7
|
-
attr_accessor :eansNotFound
|
8
|
-
attr_accessor :pageHash
|
9
|
-
attr_accessor :errors
|
10
|
-
attr_accessor :products
|
11
|
-
|
12
|
-
###
|
13
|
-
# @param \stdClass $jsonObject
|
14
|
-
# @param ModelFactoryInterface $factory
|
15
|
-
#
|
16
|
-
# @return static
|
17
|
-
###
|
18
|
-
def self.createFromJson(jsonObject, factory)
|
19
|
-
|
20
|
-
productsEansResult = self.new
|
21
|
-
productsEansResult.products = Array(nil)
|
22
|
-
productsEansResult.eansNotFound = Array(nil)
|
23
|
-
productsEansResult.errors = Array(nil)
|
24
|
-
|
25
|
-
if jsonObject["pageHash"]
|
26
|
-
productsEansResult.pageHash = jsonObject["pageHash"]
|
27
|
-
else
|
28
|
-
productsEansResult.pageHash = nil
|
29
|
-
end
|
30
|
-
|
31
|
-
if (jsonObject["eans"])
|
32
|
-
jsonObject["eans"].each do |jsonProduct|
|
33
|
-
if (jsonProduct["error_code"])
|
34
|
-
productsEansResult.errors.push(jsonProduct)
|
35
|
-
productsEansResult.eansNotFound = productsEansResult.eansNotFound + jsonProduct["ean"]
|
36
|
-
next;
|
37
|
-
end
|
38
|
-
productsEansResult.products.push(factory.createProduct(jsonProduct));
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
return productsEansResult;
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
class ProductsResult
|
5
|
-
include AbstractModel
|
6
|
-
|
7
|
-
attr_accessor :idsNotFound
|
8
|
-
attr_accessor :pageHash
|
9
|
-
attr_accessor :errors
|
10
|
-
attr_accessor :products
|
11
|
-
|
12
|
-
|
13
|
-
###
|
14
|
-
# @param \stdClass $jsonObject
|
15
|
-
# @param ModelFactoryInterface $factory
|
16
|
-
#
|
17
|
-
# @return static
|
18
|
-
###
|
19
|
-
def self.createFromJson(jsonObject, factory)
|
20
|
-
|
21
|
-
productsResult = self.new
|
22
|
-
|
23
|
-
productsResult.pageHash = (jsonObject["pageHash"]) ? jsonObject["pageHash"] : nil;
|
24
|
-
productsResult.errors=Array(nil)
|
25
|
-
productsResult.idsNotFound=Array(nil)
|
26
|
-
productsResult.products = Hash.new
|
27
|
-
|
28
|
-
if (jsonObject["ids"])
|
29
|
-
jsonObject["ids"].each do |key, jsonProduct|
|
30
|
-
if (jsonProduct["error_code"])
|
31
|
-
productsResult.idsNotFound.push(key)
|
32
|
-
productsResult.errors.push(jsonProduct);
|
33
|
-
next
|
34
|
-
end
|
35
|
-
productsResult.products[Integer(key)] = factory.createProduct(jsonProduct);
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
return productsResult;
|
40
|
-
end
|
41
|
-
|
42
|
-
###
|
43
|
-
# @return integer[] array of product ids
|
44
|
-
###
|
45
|
-
def productsNotFound()
|
46
|
-
|
47
|
-
return self.idsNotFound;
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
module ResultError
|
5
|
-
|
6
|
-
attr_accessor :errorIdent
|
7
|
-
attr_accessor :errorCode
|
8
|
-
attr_accessor :errorMessage
|
9
|
-
|
10
|
-
def initialize(jsonObject)
|
11
|
-
|
12
|
-
self.parseErrorResult(jsonObject);
|
13
|
-
end
|
14
|
-
|
15
|
-
def parseErrorResult(jsonObject)
|
16
|
-
|
17
|
-
self.errorIdent = (jsonObject.key?("error_ident")) ? String(jsonObject["error_ident"]) : nil;
|
18
|
-
self.errorCode = (jsonObject.key?("error_code")) ? Integer(jsonObject["error_code"]) : 0;
|
19
|
-
self.errorMessage = (jsonObject.key?("error_message")) ? jsonObject["error_message"] : nil;
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,255 +0,0 @@
|
|
1
|
-
module AboutYou
|
2
|
-
module SDK
|
3
|
-
module Model
|
4
|
-
|
5
|
-
class Variant
|
6
|
-
include AbstractModel
|
7
|
-
|
8
|
-
attr_accessor :factory
|
9
|
-
attr_accessor :product
|
10
|
-
attr_accessor :id
|
11
|
-
attr_accessor :images
|
12
|
-
attr_accessor :selectedImage
|
13
|
-
attr_accessor :aboutNumber
|
14
|
-
attr_accessor :facetGroups
|
15
|
-
attr_accessor :ean
|
16
|
-
attr_accessor :isDefault
|
17
|
-
attr_accessor :price
|
18
|
-
attr_accessor :oldPrice
|
19
|
-
attr_accessor :retailPrice
|
20
|
-
attr_accessor :additionalInfo
|
21
|
-
attr_accessor :quantity
|
22
|
-
attr_accessor :facetIds
|
23
|
-
attr_accessor :firstActiveDate
|
24
|
-
attr_accessor :firstSaleDate
|
25
|
-
attr_accessor :createdDate
|
26
|
-
attr_accessor :updatedDate
|
27
|
-
attr_accessor :color
|
28
|
-
attr_accessor :length
|
29
|
-
attr_accessor :seasonCode
|
30
|
-
attr_accessor :jsonObject
|
31
|
-
|
32
|
-
###
|
33
|
-
# @param \stdClass $jsonObject
|
34
|
-
# @param ModelFactoryInterface $factory
|
35
|
-
# @param Product $product
|
36
|
-
#
|
37
|
-
# @return static
|
38
|
-
###
|
39
|
-
def self.createFromJson(jsonObject, factory, product)
|
40
|
-
|
41
|
-
jsonObj = jsonObject
|
42
|
-
if (!jsonObj["id"])
|
43
|
-
raise 'MalformedJsonException'
|
44
|
-
end
|
45
|
-
|
46
|
-
variant = self.new
|
47
|
-
variant.factory = factory
|
48
|
-
variant.product = product
|
49
|
-
variant.jsonObject = jsonObject
|
50
|
-
|
51
|
-
|
52
|
-
variant.parseImages(jsonObj["images"])
|
53
|
-
#free memory
|
54
|
-
jsonObj["images"] = nil
|
55
|
-
|
56
|
-
variant.id = jsonObj["id"]
|
57
|
-
|
58
|
-
variant.aboutNumber = (jsonObj["about_number"]) ? jsonObj["about_number"] : nil
|
59
|
-
variant.ean = (jsonObj["ean"]) ? jsonObj["ean"] : nil
|
60
|
-
variant.isDefault = (jsonObj["default"]) ? jsonObj["default"] : nil
|
61
|
-
variant.price = (jsonObj["price"]) ? jsonObj["price"] : nil
|
62
|
-
variant.oldPrice = (jsonObj["old_price"]) ? jsonObj["old_price"] : nil
|
63
|
-
variant.retailPrice = (jsonObj["retail_price"]) ? jsonObj["retail_price"] : nil
|
64
|
-
variant.additionalInfo = (jsonObj["additional_info"]) ? jsonObj["additional_info"] : nil
|
65
|
-
variant.quantity = (jsonObj["quantity"]) ? jsonObj["quantity"] : 0
|
66
|
-
variant.firstActiveDate = (jsonObj["first_active_date"]) ? jsonObj["first_active_date"] : nil
|
67
|
-
variant.firstSaleDate = (jsonObj["first_sale_date"]) ? jsonObj["first_sale_date"] : nil
|
68
|
-
variant.createdDate = (jsonObj["created_date"]) ? jsonObj["created_date"] : nil
|
69
|
-
variant.updatedDate = (jsonObj["updated_date"]) ? jsonObj["updated_date"] : nil
|
70
|
-
|
71
|
-
variant.facetIds = variant.parseFacetIds(jsonObj)
|
72
|
-
variant.color = variant.facetGroup(AboutYou::SDK::Constants::FACET_COLOR, jsonObject)
|
73
|
-
variant.length = variant.facetGroup(AboutYou::SDK::Constants::FACET_LENGTH, jsonObject)
|
74
|
-
variant.seasonCode = variant.facetGroup(AboutYou::SDK::Constants::FACET_SEASON_CODE,jsonObject)
|
75
|
-
|
76
|
-
|
77
|
-
return variant
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
def parseImages(imageObject)
|
82
|
-
if (!self.images)
|
83
|
-
self.images = Array(nil);
|
84
|
-
if(imageObject)
|
85
|
-
imageObject.each do |image|
|
86
|
-
self.images.push(self.factory.createImage(image))
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
###
|
93
|
-
# Get image by given hash.
|
94
|
-
#
|
95
|
-
# @param string $hash The image hash.
|
96
|
-
#
|
97
|
-
# @return Image
|
98
|
-
###
|
99
|
-
def imageByHash(hash)
|
100
|
-
|
101
|
-
self.images.each do |image|
|
102
|
-
return image if(image.hash == hash)
|
103
|
-
end
|
104
|
-
nil
|
105
|
-
end
|
106
|
-
|
107
|
-
###
|
108
|
-
# Select a specific image.
|
109
|
-
#
|
110
|
-
# @param string $hash The image hash or null for default image.
|
111
|
-
#
|
112
|
-
# @return void
|
113
|
-
#
|
114
|
-
# @depracted
|
115
|
-
###
|
116
|
-
def selectImage(hash=nil)
|
117
|
-
if (hash)
|
118
|
-
self.selectedImage = imageByHash(hash);
|
119
|
-
else
|
120
|
-
self.selectedImage = nil;
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
###
|
125
|
-
# Get selected or default image.
|
126
|
-
#
|
127
|
-
# @return Image
|
128
|
-
###
|
129
|
-
def image
|
130
|
-
|
131
|
-
if (self.selectedImage)
|
132
|
-
return self.selectedImage;
|
133
|
-
elsif (self.images[0])
|
134
|
-
return self.images[0];
|
135
|
-
end
|
136
|
-
return nil;
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
def parseFacetIds(jsonObject)
|
141
|
-
|
142
|
-
ids = {}
|
143
|
-
if !(jsonObject["attributes"].empty?)
|
144
|
-
jsonObject["attributes"].each do |group, aIds|
|
145
|
-
gid = group[11..group.length] # rm prefix "attributs_"
|
146
|
-
ids[Integer(gid)] = aIds
|
147
|
-
end
|
148
|
-
end
|
149
|
-
return ids
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
def generateFacetGroupSet(jsonObject)
|
154
|
-
|
155
|
-
ids = self.parseFacetIds(jsonObject)
|
156
|
-
self.facetGroups= AboutYou::SDK::Model::FacetGroupSet.new(ids)
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
###
|
161
|
-
# @return FacetGroupSet
|
162
|
-
###
|
163
|
-
def facetGroupSet(jsonObject)
|
164
|
-
|
165
|
-
if !(self.facetGroups)
|
166
|
-
self.generateFacetGroupSet(jsonObject);
|
167
|
-
end
|
168
|
-
return self.facetGroups;
|
169
|
-
end
|
170
|
-
|
171
|
-
###
|
172
|
-
# @param integer $groupId
|
173
|
-
#
|
174
|
-
# @return FacetGroup|null
|
175
|
-
###
|
176
|
-
def facetGroup(groupId, jsonObject=self.jsonObject)
|
177
|
-
return self.facetGroupSet(jsonObject).group(groupId)
|
178
|
-
end
|
179
|
-
|
180
|
-
###
|
181
|
-
# @return FacetGroup|null
|
182
|
-
###
|
183
|
-
def size()
|
184
|
-
|
185
|
-
###
|
186
|
-
# @todo: Instance level caching
|
187
|
-
###
|
188
|
-
groupId = self.sizeGroupId();
|
189
|
-
|
190
|
-
if !(groupId.empty?)
|
191
|
-
return self.facetGroup(groupId);
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
###
|
196
|
-
# @return integer|null
|
197
|
-
###
|
198
|
-
def sizeGroupId()
|
199
|
-
|
200
|
-
keys = Hash.new
|
201
|
-
|
202
|
-
groups = self.facetGroupSet().groups();
|
203
|
-
|
204
|
-
if (groups.is_a? Array)
|
205
|
-
groups.each do |group|
|
206
|
-
keys[group.name] = group.groupId();
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
sizeRun = self.facetGroup(AboutYou::SDK::Constants::FACET_SIZE_RUN);
|
211
|
-
|
212
|
-
if !(sizeRun.empty?)
|
213
|
-
sizeRun.facets.each do |facet|
|
214
|
-
groupName = facet.value();
|
215
|
-
if (keys.key?(groupName))
|
216
|
-
return keys[groupName];
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
if (keys.key?('size'))
|
221
|
-
return keys['size'];
|
222
|
-
end
|
223
|
-
if (keys.key?('size_run'))
|
224
|
-
return keys['size_run'];
|
225
|
-
end
|
226
|
-
|
227
|
-
return nil;
|
228
|
-
end
|
229
|
-
|
230
|
-
###
|
231
|
-
# Returns the quantity per pack for this variant.
|
232
|
-
# By default, this returns 1. But some items can have a bigger number.
|
233
|
-
#
|
234
|
-
# @return int quantity per pack
|
235
|
-
###
|
236
|
-
def quantityPerPack()
|
237
|
-
|
238
|
-
facetGroup = self.facetGroup(AboutYou::SDK::Constants::FACET_QUANTITY_PER_PACK);
|
239
|
-
|
240
|
-
if !(facetGroup)
|
241
|
-
return 1;
|
242
|
-
end
|
243
|
-
|
244
|
-
facets = facetGroup.facets();
|
245
|
-
|
246
|
-
if !(facets)
|
247
|
-
return 1;
|
248
|
-
end
|
249
|
-
|
250
|
-
return facets[0].value();
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|