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.
Files changed (91) hide show
  1. checksums.yaml +8 -8
  2. data/lib/{aboutyou-sdk/CacheProvider/Dalli.rb → AboutYou/CacheProvider/dalli.rb} +18 -19
  3. data/lib/{aboutyou-sdk/CacheProvider/Redis.rb → AboutYou/CacheProvider/redis.rb} +19 -20
  4. data/lib/{aboutyou-sdk/Criteria/ProductFields.rb → AboutYou/Criteria/product_fields.rb} +25 -27
  5. data/lib/{aboutyou-sdk/Criteria/ProductSearchCriteria.rb → AboutYou/Criteria/product_search_criteria.rb} +128 -123
  6. data/lib/{aboutyou-sdk/Factory/DefaultModelFactory.rb → AboutYou/Factory/default_model_factory.rb} +267 -224
  7. data/lib/AboutYou/Model/Basket/abstract_basket_item.rb +57 -0
  8. data/lib/AboutYou/Model/Basket/basket_item.rb +95 -0
  9. data/lib/AboutYou/Model/Basket/basket_set.rb +199 -0
  10. data/lib/AboutYou/Model/Basket/basket_set_item.rb +54 -0
  11. data/lib/AboutYou/Model/Basket/basket_variant_item.rb +123 -0
  12. data/lib/{aboutyou-sdk/Model/CategoryManager/DefaultCategoryManager.rb → AboutYou/Model/CategoryManager/default_category_manager.rb} +80 -65
  13. data/lib/{aboutyou-sdk/Model/FacetManager/DefaultFacetManager.rb → AboutYou/Model/FacetManager/default_facet_manager.rb} +58 -50
  14. data/lib/{aboutyou-sdk/Model/ProductSearchResult/FacetCount.rb → AboutYou/Model/ProductSearchResult/facet_count.rb} +2 -3
  15. data/lib/AboutYou/Model/ProductSearchResult/facet_counts.rb +67 -0
  16. data/lib/{aboutyou-sdk/Model/ProductSearchResult/PriceRange.rb → AboutYou/Model/ProductSearchResult/price_range.rb} +17 -18
  17. data/lib/AboutYou/Model/ProductSearchResult/sale_counts.rb +79 -0
  18. data/lib/AboutYou/Model/ProductSearchResult/terms_count.rb +40 -0
  19. data/lib/{aboutyou-sdk/Model/AbstractModel.rb → AboutYou/Model/abstract_model.rb} +2 -3
  20. data/lib/{aboutyou-sdk/Model/App.rb → AboutYou/Model/app.rb} +15 -15
  21. data/lib/{aboutyou-sdk/Model/Autocomplete.rb → AboutYou/Model/autocomplete.rb} +25 -32
  22. data/lib/AboutYou/Model/basket.rb +235 -0
  23. data/lib/AboutYou/Model/categories_result.rb +24 -0
  24. data/lib/AboutYou/Model/category.rb +102 -0
  25. data/lib/AboutYou/Model/category_tree.rb +37 -0
  26. data/lib/AboutYou/Model/facet.rb +86 -0
  27. data/lib/AboutYou/Model/facet_group.rb +96 -0
  28. data/lib/AboutYou/Model/facet_group_set.rb +209 -0
  29. data/lib/AboutYou/Model/image.rb +102 -0
  30. data/lib/{aboutyou-sdk/Model/ImageSize.rb → AboutYou/Model/image_size.rb} +9 -5
  31. data/lib/AboutYou/Model/initiate_order.rb +53 -0
  32. data/lib/AboutYou/Model/order.rb +22 -0
  33. data/lib/AboutYou/Model/product.rb +353 -0
  34. data/lib/AboutYou/Model/product_search_result.rb +114 -0
  35. data/lib/AboutYou/Model/products_ean_result.rb +43 -0
  36. data/lib/AboutYou/Model/products_result.rb +56 -0
  37. data/lib/AboutYou/Model/result_error.rb +28 -0
  38. data/lib/AboutYou/Model/variant.rb +214 -0
  39. data/lib/AboutYou/Model/variants_result.rb +91 -0
  40. data/lib/AboutYou/client.rb +128 -0
  41. data/lib/{aboutyou-sdk/Constants.rb → AboutYou/constants.rb} +3 -5
  42. data/lib/AboutYou/query.rb +343 -0
  43. data/lib/AboutYou/query_builder.rb +530 -0
  44. data/lib/ay.rb +566 -0
  45. data/tests/Sinatra-test/Main.rb +3 -0
  46. data/tests/testAutocomplete.rb +5 -6
  47. data/tests/testCatFilter.rb +8 -9
  48. data/tests/testCatTree.rb +3 -3
  49. data/tests/testCategoryCaching.rb +4 -5
  50. data/tests/{testFacetCaching.rb → testDalliCache.rb} +4 -5
  51. data/tests/testFacetTypes.rb +5 -6
  52. data/tests/testFacets.rb +7 -8
  53. data/tests/testFetchFacet.rb +5 -6
  54. data/tests/testJavaScript.rb +3 -4
  55. data/tests/testProdCatLongestPath.rb +7 -8
  56. data/tests/testProductSearchResult.rb +6 -7
  57. data/tests/testProductsByEans.rb +6 -7
  58. data/tests/testProductsByIds.rb +6 -7
  59. data/tests/testRedisCache.rb +4 -5
  60. data/tests/testSuggest.rb +5 -6
  61. data/tests/testVariantsByIds.rb +7 -8
  62. metadata +46 -46
  63. data/lib/aboutyou-sdk.rb +0 -596
  64. data/lib/aboutyou-sdk/Client.rb +0 -134
  65. data/lib/aboutyou-sdk/Model/Basket.rb +0 -268
  66. data/lib/aboutyou-sdk/Model/Basket/AbstractBasketItem.rb +0 -76
  67. data/lib/aboutyou-sdk/Model/Basket/BasketItem.rb +0 -100
  68. data/lib/aboutyou-sdk/Model/Basket/BasketSet.rb +0 -192
  69. data/lib/aboutyou-sdk/Model/Basket/BasketSetItem.rb +0 -46
  70. data/lib/aboutyou-sdk/Model/Basket/BasketVariantItem.rb +0 -137
  71. data/lib/aboutyou-sdk/Model/CategoriesResult.rb +0 -15
  72. data/lib/aboutyou-sdk/Model/Category.rb +0 -126
  73. data/lib/aboutyou-sdk/Model/CategoryTree.rb +0 -35
  74. data/lib/aboutyou-sdk/Model/Facet.rb +0 -105
  75. data/lib/aboutyou-sdk/Model/FacetGroup.rb +0 -110
  76. data/lib/aboutyou-sdk/Model/FacetGroupSet.rb +0 -242
  77. data/lib/aboutyou-sdk/Model/Image.rb +0 -134
  78. data/lib/aboutyou-sdk/Model/InitiateOrder.rb +0 -50
  79. data/lib/aboutyou-sdk/Model/Order.rb +0 -17
  80. data/lib/aboutyou-sdk/Model/Product.rb +0 -335
  81. data/lib/aboutyou-sdk/Model/ProductSearchResult.rb +0 -125
  82. data/lib/aboutyou-sdk/Model/ProductSearchResult/FacetCounts.rb +0 -59
  83. data/lib/aboutyou-sdk/Model/ProductSearchResult/SaleCounts.rb +0 -71
  84. data/lib/aboutyou-sdk/Model/ProductSearchResult/TermsCount.rb +0 -36
  85. data/lib/aboutyou-sdk/Model/ProductsEansResult.rb +0 -47
  86. data/lib/aboutyou-sdk/Model/ProductsResult.rb +0 -52
  87. data/lib/aboutyou-sdk/Model/ResultError.rb +0 -24
  88. data/lib/aboutyou-sdk/Model/Variant.rb +0 -255
  89. data/lib/aboutyou-sdk/Model/VariantsResult.rb +0 -102
  90. data/lib/aboutyou-sdk/Query.rb +0 -350
  91. data/lib/aboutyou-sdk/QueryBuilder.rb +0 -499
@@ -1,7 +1,6 @@
1
1
  module AboutYou
2
2
  module SDK
3
3
  module Model
4
-
5
4
  ###
6
5
  # This class represents a FacetCount model.
7
6
  #
@@ -19,7 +18,7 @@ module AboutYou
19
18
  # * *Args* :
20
19
  # - +facet+ -> a facet
21
20
  # - +count+ -> the count of the facet
22
- #
21
+ #
23
22
  # * *Returns* :
24
23
  # - Instance of AboutYou::SDK::Model::FacetCount
25
24
  ###
@@ -30,4 +29,4 @@ module AboutYou
30
29
  end
31
30
  end
32
31
  end
33
- end
32
+ end
@@ -0,0 +1,67 @@
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 group_id of the facetcounts
11
+ attr_accessor :group_id
12
+ # an array of facetcount objects
13
+ attr_accessor :facet_count_list
14
+ # the cont of the products
15
+ attr_accessor :product_count_total
16
+ # the count of the products without facets
17
+ attr_accessor :product_count_without_any_facet
18
+ # the count of the procuts with other facets
19
+ attr_accessor :product_count_with_other_facet
20
+
21
+ ###
22
+ # the Constructor for the facetcounts class
23
+ #
24
+ # * *Args* :
25
+ # - +product_count_total+ -> the total productcount
26
+ # - +product_count_with_other_facet+ -> the productcount without any facets
27
+ # - +product_count_without_any_facet+ -> the productcount with other facets
28
+ #
29
+ # * *Returns* :
30
+ # - Instance of AboutYou::SDK::Model::FacetCounts
31
+ ###
32
+ def initialize(
33
+ product_count_total,
34
+ product_count_with_other_facet,
35
+ product_count_without_any_facet
36
+ )
37
+ self.product_count_total = product_count_total
38
+ self.product_count_with_other_facet = product_count_with_other_facet
39
+ self.product_count_without_any_facet = product_count_without_any_facet
40
+ end
41
+
42
+ ###
43
+ # This method is used for creating an instance of this class by a json_object.
44
+ #
45
+ # * *Args* :
46
+ # - +group_id+ -> the groupId of the facetcounts
47
+ # - +json_object+ -> the jsonObject received from the api
48
+ # - +facet_count_list+ -> a list of facetcount objects
49
+ #
50
+ # * *Returns* :
51
+ # - Instance of AboutYou::SDK::Model::FacetCounts
52
+ ###
53
+ def self.create_from_json(group_id, json_object, facet_count_list)
54
+ facet_counts = new(
55
+ json_object['total'],
56
+ json_object['other'],
57
+ json_object['missing']
58
+ )
59
+ facet_counts.group_id = group_id
60
+ facet_counts.facet_count_list = facet_count_list
61
+
62
+ facet_counts
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -8,7 +8,7 @@ module AboutYou
8
8
  ###
9
9
  class PriceRange
10
10
  # the product count
11
- attr_accessor :productCount
11
+ attr_accessor :product_count
12
12
  # startpoint of the price range
13
13
  attr_accessor :from
14
14
  # end of the price range
@@ -17,35 +17,34 @@ module AboutYou
17
17
  attr_accessor :min
18
18
  # max value of the price range
19
19
  attr_accessor :max
20
- #
20
+ #
21
21
  attr_accessor :mean
22
- #
22
+ #
23
23
  attr_accessor :sum
24
24
 
25
-
26
25
  ###
27
- # This method is used for creating an instance of this class by a jsonObject.
26
+ # This method is used for creating an instance of this class by a json_object.
28
27
  #
29
28
  # * *Args* :
30
- # - +jsonObject+ -> the jsonObject received from the api
31
- #
29
+ # - +json_object+ -> the jsonObject received from the api
30
+ #
32
31
  # * *Returns* :
33
32
  # - Instance of AboutYou::SDK::Model::PriceRange
34
33
  ###
35
- def self.createFromJson(jsonObject)
36
- priceRange = self.new
34
+ def self.create_from_json(json_object)
35
+ price_range = new
37
36
 
38
- priceRange.productCount = jsonObject["count"]
39
- priceRange.from = jsonObject["from"]
40
- priceRange.to = jsonObject["to"]
41
- priceRange.min = jsonObject["min"]
42
- priceRange.max = jsonObject["max"]
43
- priceRange.mean = jsonObject["mean"]
44
- priceRange.sum = jsonObject["total"]
37
+ price_range.product_count = json_object['count']
38
+ price_range.from = json_object['from']
39
+ price_range.to = json_object['to']
40
+ price_range.min = json_object['min']
41
+ price_range.max = json_object['max']
42
+ price_range.mean = json_object['mean']
43
+ price_range.sum = json_object['total']
45
44
 
46
- priceRange
45
+ price_range
47
46
  end
48
47
  end
49
48
  end
50
49
  end
51
- end
50
+ end
@@ -0,0 +1,79 @@
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
+ # count of products in sale
11
+ attr_accessor :product_count_in_sale
12
+ # count of prodocuts not in sale
13
+ attr_accessor :product_count_not_in_sale
14
+ # count of total products
15
+ attr_accessor :product_count_total
16
+ # count of products without facet
17
+ attr_accessor :product_count_without_any_facet
18
+ # count of products with other facets
19
+ attr_accessor :product_count_with_other_facet
20
+
21
+ ###
22
+ # the Constructor for the sale counts class
23
+ #
24
+ # * *Args* :
25
+ # - +product_count_total+ -> the total productcount
26
+ # - +product_count_with_other_facet+ -> the productcount without any facets
27
+ # - +product_count_without_any_facet+ -> the productcount with other facets
28
+ #
29
+ # * *Returns* :
30
+ # - Instance of AboutYou::SDK::Model::SaleCounts
31
+ ###
32
+ def initialize(product_count_total,
33
+ product_count_with_other_facet,
34
+ product_count_without_any_facet
35
+ )
36
+ self.product_count_total = product_count_total
37
+ self.product_count_with_other_facet = product_count_with_other_facet
38
+ self.product_count_without_any_facet = product_count_without_any_facet
39
+ end
40
+
41
+ ###
42
+ # This method is used for creating an instance of this class by a json_object.
43
+ #
44
+ # * *Args* :
45
+ # - +json_object+ -> the jsonObject received from the api
46
+ #
47
+ # * *Returns* :
48
+ # - Instance of AboutYou::SDK::Model::SaleCounts
49
+ ###
50
+ def self.create_from_json(json_object)
51
+ sale_counts = new(
52
+ json_object['total'],
53
+ json_object['other'],
54
+ json_object['missing']
55
+ )
56
+ sale_counts.parse_terms(json_object['terms'])
57
+
58
+ sale_counts
59
+ end
60
+
61
+ ###
62
+ # This method is used for parsing the terms of the json_object
63
+ #
64
+ # * *Args* :
65
+ # - +jsonTerms+ -> the terms of the json_object received from the api
66
+ ###
67
+ def parse_terms(json_terms)
68
+ json_terms.each do |term|
69
+ if term['term'] == 0
70
+ self.product_count_not_in_sale = term['count']
71
+ else
72
+ self.product_count_in_sale = term['count']
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,40 @@
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 :product_count_total
12
+ # count of products without facet
13
+ attr_accessor :product_count_with_other_facet
14
+ # count of products with other facets
15
+ attr_accessor :product_count_without_any_facet
16
+
17
+ ###
18
+ # the Constructor for the terms count class
19
+ #
20
+ # * *Args* :
21
+ # - +product_count_total+ -> the total productcount
22
+ # - +product_count_with_other_facet+ -> the productcount without any facets
23
+ # - +product_count_without_any_facet+ -> the productcount with other facets
24
+ #
25
+ # * *Returns* :
26
+ # - Instance of AboutYou::SDK::Model::TermsCount
27
+ ###
28
+ def initialize(
29
+ product_count_total,
30
+ product_count_with_other_facet,
31
+ product_count_without_any_facet
32
+ )
33
+ self.productCountTotal = product_count_total
34
+ self.product_count_with_other_facet = product_count_with_other_facet
35
+ self.product_count_without_any_facet = product_count_without_any_facet
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,14 +1,13 @@
1
1
  module AboutYou
2
2
  module SDK
3
3
  module Model
4
-
5
4
  ###
6
- # This Module is abstract and represents a model which has a shopApi attribute
5
+ # This Module is abstract and represents a model which has a shop_api attribute
7
6
  #
8
7
  # author:: Collins GmbH & Co KG
9
8
  ###
10
9
  module AbstractModel
11
- attr_accessor :shopApi
10
+ attr_accessor :shop_api
12
11
  end
13
12
  end
14
13
  end
@@ -10,38 +10,38 @@ module AboutYou
10
10
  # the id of the app
11
11
  attr_accessor :id
12
12
  # the logo url of the app
13
- attr_accessor :logoUrl
13
+ attr_accessor :logo_url
14
14
  # the name of the app
15
15
  attr_accessor :name
16
16
  # the url of the app
17
17
  attr_accessor :url
18
18
  # the privacy statement url
19
- attr_accessor :privacyStatementUrl
19
+ attr_accessor :privacy_statement_url
20
20
  # the tearms of service url
21
- attr_accessor :tosUrl
21
+ attr_accessor :tos_url
22
22
 
23
23
  ###
24
- # This method is used for creating an instance of this class by a jsonObject.
24
+ # This method is used for creating an instance of this class by a json_object.
25
25
  #
26
26
  # * *Args* :
27
- # - +json+ -> the jsonObject received from the api
28
- #
27
+ # - +json+ -> the json_object received from the api
28
+ #
29
29
  # * *Returns* :
30
30
  # - Instance of AboutYou::SDK::Model::App
31
31
  ###
32
- def self.createFromJson(json)
33
- app = self.new
32
+ def self.create_from_json(json)
33
+ app = new
34
34
 
35
- app.id = json["id"]
36
- app.logoUrl = json["logo_url"]
37
- app.name = json["name"]
38
- app.url = json["url"]
39
- app.privacyStatementUrl = json["privacy_statement_url"]
40
- app.tosUrl = json["tos_url"]
35
+ app.id = json['id']
36
+ app.logo_url = json['logo_url']
37
+ app.name = json['name']
38
+ app.url = json['url']
39
+ app.privacy_statement_url = json['privacy_statement_url']
40
+ app.tos_url = json['tos_url']
41
41
 
42
42
  app
43
43
  end
44
44
  end
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -19,9 +19,9 @@ module AboutYou
19
19
  # the Constructor for the autocomplete class
20
20
  #
21
21
  # * *Args* :
22
- # - +productCountTotal+ -> the total productcount
23
- # - +productCountWithOtherFacet+ -> the productcount without any facets
24
- #
22
+ # - +product_count_total+ -> the total productcount
23
+ # - +product_count_with_other_facet+ -> the productcount without any facets
24
+ #
25
25
  # * *Returns* :
26
26
  # - Instance of AboutYou::SDK::Model::AutoComplete
27
27
  ###
@@ -34,38 +34,36 @@ module AboutYou
34
34
  # This method lets you build an autocomplete model by a json response from the api
35
35
  #
36
36
  # * *Args* :
37
- # - +jsonObject+ -> the json response from the api
37
+ # - +json_object+ -> the json response from the api
38
38
  # - +factory+ -> the model factory responsible for building the models
39
- #
39
+ #
40
40
  # * *Returns* :
41
41
  # - Instance of AboutYou::SDK::Model::AutoComplete
42
42
  ###
43
- def self.createFromJson(jsonObject, factory)
44
- self.new(parseCategories(jsonObject, factory), parseProducts(jsonObject, factory))
43
+ def self.create_from_json(json_object, factory)
44
+ new(
45
+ parse_categories(json_object, factory),
46
+ parse_products(json_object, factory)
47
+ )
45
48
  end
46
49
 
47
50
  ###
48
51
  # This method parses the json object and builds category models from it
49
52
  #
50
53
  # * *Args* :
51
- # - +jsonObject+ -> the json response from the api
54
+ # - +json_object+ -> the json response from the api
52
55
  # - +factory+ -> the model factory responsible for building the models
53
- #
56
+ #
54
57
  # * *Returns* :
55
58
  # - Array containing instances of AboutYou::SDK::Model::Category
56
59
  ###
57
- def self.parseCategories(jsonObject, factory)
58
- unless jsonObject.key?('categories')
59
- return NOT_REQUESTED
60
- end
61
-
62
- if jsonObject["categories"] == nil
63
- return []
64
- end
60
+ def self.parse_categories(json_object, factory)
61
+ return NOT_REQUESTED unless json_object.key?('categories')
62
+ return [] if json_object['categories'].nil?
65
63
 
66
64
  categories = []
67
- jsonObject["categories"].each do |category|
68
- categories.push(factory.createCategory(category))
65
+ json_object['categories'].each do |category|
66
+ categories.push(factory.create_category(category))
69
67
  end
70
68
 
71
69
  categories
@@ -75,24 +73,19 @@ module AboutYou
75
73
  # This method parses the json object and builds product models from it
76
74
  #
77
75
  # * *Args* :
78
- # - +jsonObject+ -> the json response from the api
76
+ # - +json_object+ -> the json response from the api
79
77
  # - +factory+ -> the model factory responsible for building the models
80
- #
78
+ #
81
79
  # * *Returns* :
82
80
  # - Array containing instances of AboutYou::SDK::Model::Product
83
81
  ###
84
- def self.parseProducts(jsonObject, factory)
85
- unless jsonObject.key?('products')
86
- return NOT_REQUESTED
87
- end
88
-
89
- if jsonObject["products"] == nil
90
- return []
91
- end
82
+ def self.parse_products(json_object, factory)
83
+ return NOT_REQUESTED unless json_object.key?('products')
84
+ return [] if json_object['products'].nil?
92
85
 
93
86
  products = []
94
- jsonObject["products"].each do |product|
95
- products.push(factory.createProduct(product))
87
+ json_object['products'].each do |product|
88
+ products.push(factory.create_product(product))
96
89
  end
97
90
 
98
91
  products
@@ -100,4 +93,4 @@ module AboutYou
100
93
  end
101
94
  end
102
95
  end
103
- end
96
+ end
@@ -0,0 +1,235 @@
1
+ module AboutYou
2
+ module SDK
3
+ module Model
4
+ ###
5
+ # This Class represents a basket model
6
+ #
7
+ # author:: Collins GmbH & Co KG
8
+ ###
9
+ class Basket
10
+ # array of items in the basket
11
+ attr_accessor :items
12
+ # errors of the basket
13
+ attr_accessor :errors
14
+ attr_accessor :unique_variant_count
15
+ attr_accessor :products
16
+ attr_accessor :total_price
17
+ attr_accessor :total_net
18
+ attr_accessor :total_vat
19
+ attr_accessor :total_amount
20
+ attr_accessor :deleted_items
21
+ attr_accessor :updated_items
22
+
23
+ ###
24
+ # @param object $json_object
25
+ # @param ModelFactoryInterface $factory
26
+ #
27
+ # @return Basket
28
+ ###
29
+ def self.create_from_json(json_object, factory)
30
+ basket = new
31
+ basket.errors = {}
32
+ basket.deleted_items = {}
33
+ basket.updated_items = {}
34
+ basket.total_price = json_object['total_price']
35
+ basket.total_net = json_object['total_net']
36
+ basket.total_vat = json_object['total_vat']
37
+ basket.parse_items(json_object, factory)
38
+ basket.total_amount = items.count
39
+
40
+ basket
41
+ end
42
+
43
+ ###
44
+ # @return boolean
45
+ ###
46
+ def errors?
47
+ errors.count > 0
48
+ end
49
+
50
+ ###
51
+ # @param $itemId
52
+ #
53
+ # @return BasketItem|BasketSet|null
54
+ ###
55
+ def item(item_id)
56
+ return items[item_id] if items.key?(item_id)
57
+ end
58
+
59
+ def collected_items
60
+ items = self.items
61
+ items_merged = {}
62
+ items.each do |item|
63
+ key = item.unique_key
64
+ if items_merged.key?(key)
65
+ amount = items_merged[key]['amount'] + 1
66
+ items_merged[key] = {
67
+ 'item' => item,
68
+ 'price' => item.total_price * amount,
69
+ 'amount' => amount
70
+ }
71
+ else
72
+ items_merged[key] = {
73
+ 'item' => item,
74
+ 'price' => item.total_price,
75
+ 'amount' => 1
76
+ }
77
+ end
78
+ end
79
+
80
+ items_merged
81
+ end
82
+
83
+ ###
84
+ # build order line for update query
85
+ # @return array
86
+ ###
87
+ def order_lines_array
88
+ order_lines = []
89
+
90
+ deleted_items.uniq.each do |itemId|
91
+ order_lines.push('delete' => itemId)
92
+ end
93
+
94
+ updatedItems.each do |item|
95
+ order_lines.push(item)
96
+ end
97
+
98
+ order_lines
99
+ end
100
+
101
+ def parse_items(json_object, factory)
102
+ products = {}
103
+
104
+ json_object['products'].each do |key, json_product|
105
+ products[key] = factory.create_product(json_product)
106
+ end if json_object['products']
107
+
108
+ self.products = products
109
+ vids = []
110
+
111
+ json_object['order_lines'].each do |key, json_item|
112
+ if json_item['set_items']
113
+ item = factory.create_basket_set(json_item, products)
114
+ else
115
+ vids.push(json_item['variantId'])
116
+ item = factory.create_basket_item(json_item, products)
117
+ end
118
+
119
+ if item.errors?
120
+ errors[key] = item
121
+ else
122
+ items[item.id] = item
123
+ end
124
+ end if json_object['order_lines']
125
+
126
+ vids = vids.uniq
127
+ self.uniqueVariantCount = vids.count
128
+ end
129
+
130
+ ###
131
+ # @param string $itemId
132
+ #
133
+ # @return $this
134
+ ###
135
+ def delete_item(item_id)
136
+ deleted_items[item_id] = item_id
137
+
138
+ self
139
+ end
140
+
141
+ ###
142
+ # @param string[] $itemIds
143
+ #
144
+ # @return $this
145
+ ###
146
+ def delete_items(item_ids)
147
+ item_ids.each do |item_id|
148
+ deleted_items[item_id] = item_id
149
+ end
150
+
151
+ self
152
+ end
153
+
154
+ ###
155
+ # @return $this
156
+ ###
157
+ def delete_all_items
158
+ items = self.items
159
+
160
+ return self unless items.empty?
161
+ ids = []
162
+ items.each do |item|
163
+ ids.push = item.id
164
+ end
165
+ delete_items(ids)
166
+
167
+ self
168
+ end
169
+
170
+ ###
171
+ # @param BasketItem $basketItem
172
+ #
173
+ # @return $this
174
+ ###
175
+ def update_item(basket_item)
176
+ item = {
177
+ 'id' => basket_item.id,
178
+ 'variant_id' => basket_item.variant_id,
179
+ 'app_id' => basket_item.app_id
180
+ }
181
+ add_data = basket_item.additional_data
182
+ if add_data
183
+ check_additional_data(add_data)
184
+ item['additional_data'] = add_data
185
+ end
186
+ updated_items[basket_item.id] = item
187
+
188
+ self
189
+ end
190
+
191
+ ###
192
+ # @param BasketSet $basketSet
193
+ #
194
+ # @return $this
195
+ ###
196
+ def update_item_set(basket_set)
197
+ items = basket_set.items
198
+
199
+ fail 'InvalidArgumentException! BasketSet
200
+ needs at least one item' if items.empty?
201
+
202
+ item_set = []
203
+ items.each do |sub_item|
204
+ item = {
205
+ 'variant_id' => sub_item.variant_id,
206
+ 'app_id' => sub_item.app_id
207
+ }
208
+ add_data = sub_item.additional_data
209
+ if add_data
210
+ check_additional_data(add_data)
211
+ item['additional_data'] = add_data
212
+ end
213
+ item_set.push = item
214
+ end
215
+
216
+ updated_items[basket_set.id] = {
217
+ 'id' => basket_set.id,
218
+ 'additional_data' => basket_set.additional_data,
219
+ 'set_items' => item_set
220
+ }
221
+
222
+ self
223
+ end
224
+
225
+ def check_additional_data(add_data = nil, _img_url_required = false)
226
+ fail 'InvalidArgumentException! description is required
227
+ in additional data' if add_data && !add_data.key?('description')
228
+ fail 'InvalidArgumentException! internal_infos must be an array' if
229
+ add_data.key?('internal_infos') &&
230
+ !add_data['internal_infos'].is_a?(Array)
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end