spree_api 3.7.0.rc2 → 3.7.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27ba29a8ab5de5c7606f6707d735c73063ee4525961d8e22906b9145af89a9de
4
- data.tar.gz: 4cc4d78e86ac737ce57d57c27a72f9759038edd6196b9315debdd9dda0cdc31f
3
+ metadata.gz: bb5034c1887c750d3b1437db3d0a922dc85a2b918362398e5fd09d23ad53cad0
4
+ data.tar.gz: 8bc92a25c619d9569861bdf0c2bb95a95fbfc06ad1776eb47c80d734c01e4a47
5
5
  SHA512:
6
- metadata.gz: 1fb141c57d7361926931e1a812273bbbee9f632fa2a8ff0755229b1abd0dfedcd36f504676516410f136190de522415c0f8e2497ad93936a4d774a67fa0c1fff
7
- data.tar.gz: c8f51c67395b4b68133b856e9844b216cbfed071d0de7a4ae0a7a4053e4ac0053bfd5ba30fc95e46edf1532a3be220e951ae06c90f4b8700c574e2bdaca4b703
6
+ metadata.gz: deed5581a6699910b7ef95e4f3674f1c090a1a0a2f54e47f0f2789b9962a9dd596d7c94416222ccc871a99756037601b4587f0bab673e33cb60323f38c4f47ae
7
+ data.tar.gz: ee2ae411b29c449168adf4d8ebf9226500fd8414638ac4c9e29daa921483f408de143e0cbbddc85a46e88aa14a99beab8071f30b7b4ed1d847a420d16a9942d2
@@ -26,7 +26,7 @@ module Spree
26
26
  end
27
27
 
28
28
  def find_spree_current_order
29
- Spree::Orders::FindCurrent.new.execute(
29
+ Spree::Api::Dependencies.storefront_current_order_finder.constantize.new.execute(
30
30
  store: spree_current_store,
31
31
  user: spree_current_user,
32
32
  token: order_token,
@@ -35,7 +35,7 @@ module Spree
35
35
  end
36
36
 
37
37
  def serialize_order(order)
38
- dependencies[:cart_serializer].new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
38
+ resource_serializer.new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
39
39
  end
40
40
 
41
41
  def serialized_current_order
@@ -107,7 +107,7 @@ module Spree
107
107
  end
108
108
 
109
109
  def current_ability
110
- Spree::Ability.new(current_api_user)
110
+ Spree::Dependencies.ability_class.constantize.new(current_api_user)
111
111
  end
112
112
 
113
113
  def invalid_resource!(resource)
@@ -11,10 +11,10 @@ module Spree
11
11
  def create
12
12
  variant = Spree::Variant.find(params[:line_item][:variant_id])
13
13
 
14
- @line_item = Spree::Cart::AddItem.call(order: order,
15
- variant: variant,
16
- quantity: params[:line_item][:quantity],
17
- options: line_item_params[:options]).value
14
+ @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: order,
15
+ variant: variant,
16
+ quantity: params[:line_item][:quantity],
17
+ options: line_item_params[:options]).value
18
18
  if @line_item.errors.empty?
19
19
  respond_with(@line_item, status: 201, default_template: :show)
20
20
  else
@@ -25,7 +25,7 @@ module Spree
25
25
  def update
26
26
  @line_item = find_line_item
27
27
 
28
- if Spree::Cart::Update.call(order: @order, params: line_items_attributes).success?
28
+ if Spree::Dependencies.cart_update_service.constantize.call(order: @order, params: line_items_attributes).success?
29
29
  @line_item.reload
30
30
  respond_with(@line_item, default_template: :show)
31
31
  else
@@ -35,7 +35,7 @@ module Spree
35
35
 
36
36
  def destroy
37
37
  @line_item = find_line_item
38
- Spree::Cart::RemoveLineItem.new.call(order: @order, line_item: @line_item)
38
+ Spree::Dependencies.cart_remove_line_item_service.constantize.call(order: @order, line_item: @line_item)
39
39
 
40
40
  respond_with(@line_item, status: 204)
41
41
  end
@@ -25,10 +25,10 @@ module Spree
25
25
  quantity = params[:quantity].to_i
26
26
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
27
27
 
28
- @line_item = Spree::Cart::AddItem.call(order: @order,
29
- variant: variant,
30
- quantity: quantity,
31
- options: { shipment: @shipment }).value
28
+ @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: @order,
29
+ variant: variant,
30
+ quantity: quantity,
31
+ options: { shipment: @shipment }).value
32
32
 
33
33
  respond_with(@shipment.reload, default_template: :show)
34
34
  end
@@ -59,10 +59,10 @@ module Spree
59
59
  def add
60
60
  quantity = params[:quantity].to_i
61
61
 
62
- Spree::Cart::AddItem.call(order: @shipment.order,
63
- variant: variant,
64
- quantity: quantity,
65
- options: { shipment: @shipment })
62
+ Spree::Dependencies.cart_add_item_service.constantize.call(order: @shipment.order,
63
+ variant: variant,
64
+ quantity: quantity,
65
+ options: { shipment: @shipment })
66
66
 
67
67
  respond_with(@shipment, default_template: :show)
68
68
  end
@@ -74,7 +74,10 @@ module Spree
74
74
  @shipment.inventory_units_for(variant).sum(:quantity)
75
75
  end
76
76
 
77
- Spree::Cart::RemoveItem.call(order: @shipment.order, variant: variant, quantity: quantity, options: { shipment: @shipment })
77
+ Spree::Dependencies.cart_remove_item_service.constantize.call(order: @shipment.order,
78
+ variant: variant,
79
+ quantity: quantity,
80
+ options: { shipment: @shipment })
78
81
 
79
82
  if @shipment.inventory_units.any?
80
83
  @shipment.reload
@@ -9,6 +9,10 @@ module Spree
9
9
 
10
10
  private
11
11
 
12
+ def collection_paginator
13
+ Spree::Api::Dependencies.storefront_collection_paginator.constantize
14
+ end
15
+
12
16
  def render_serialized_payload(status = 200)
13
17
  render json: yield, status: status
14
18
  rescue ArgumentError => exception
@@ -41,7 +45,7 @@ module Spree
41
45
 
42
46
  # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
43
47
  def current_ability
44
- @current_ability ||= Spree::Ability.new(spree_current_user)
48
+ @current_ability ||= Spree::Dependencies.ability_class.constantize.new(spree_current_user)
45
49
  end
46
50
 
47
51
  def request_includes
@@ -17,19 +17,23 @@ module Spree
17
17
  private
18
18
 
19
19
  def resource
20
- dependencies[:resource_finder].new.execute(scope: scope, params: params)
20
+ resource_finder.new.execute(scope: scope, params: params)
21
21
  end
22
22
 
23
- def dependencies
24
- {
25
- resource_finder: Spree::CreditCards::Find,
26
- collection_serializer: Spree::V2::Storefront::CreditCardSerializer,
27
- resource_serializer: Spree::V2::Storefront::CreditCardSerializer
28
- }
23
+ def collection_serializer
24
+ Spree::Api::Dependencies.storefront_credit_card_serializer.constantize
25
+ end
26
+
27
+ def resource_serializer
28
+ Spree::Api::Dependencies.storefront_credit_card_serializer.constantize
29
+ end
30
+
31
+ def resource_finder
32
+ Spree::Api::Dependencies.storefront_credit_card_finder.constantize
29
33
  end
30
34
 
31
35
  def serialize_collection(collection)
32
- dependencies[:collection_serializer].new(
36
+ collection_serializer.new(
33
37
  collection,
34
38
  include: resource_includes,
35
39
  fields: sparse_fields
@@ -37,7 +41,7 @@ module Spree
37
41
  end
38
42
 
39
43
  def serialize_resource(resource)
40
- dependencies[:resource_serializer].new(
44
+ resource_serializer.new(
41
45
  resource,
42
46
  include: resource_includes,
43
47
  fields: sparse_fields
@@ -20,48 +20,61 @@ module Spree
20
20
  private
21
21
 
22
22
  def paginated_collection
23
- dependencies[:collection_paginator].new(sorted_collection, params).call
23
+ collection_paginator.new(sorted_collection, params).call
24
24
  end
25
25
 
26
26
  def sorted_collection
27
- dependencies[:collection_sorter].new(collection, params).call
27
+ collection_sorter.new(collection, params).call
28
28
  end
29
29
 
30
30
  def collection
31
- dependencies[:collection_finder].new(user: spree_current_user).execute
31
+ collection_finder.new(user: spree_current_user).execute
32
32
  end
33
33
 
34
34
  def resource
35
- resource = dependencies[:resource_finder].new(user: spree_current_user, number: params[:id]).execute.take
35
+ resource = resource_finder.new(user: spree_current_user, number: params[:id]).execute.take
36
36
  raise ActiveRecord::RecordNotFound if resource.nil?
37
37
 
38
38
  resource
39
39
  end
40
40
 
41
41
  def serialize_collection(collection)
42
- dependencies[:collection_serializer].new(
42
+ collection_serializer.new(
43
43
  collection,
44
44
  collection_options(collection)
45
45
  ).serializable_hash
46
46
  end
47
47
 
48
48
  def serialize_resource(resource)
49
- dependencies[:resource_serializer].new(
49
+ resource_serializer.new(
50
50
  resource,
51
51
  include: resource_includes,
52
52
  sparse_fields: sparse_fields
53
53
  ).serializable_hash
54
54
  end
55
55
 
56
- def dependencies
57
- {
58
- collection_sorter: Spree::Orders::Sort,
59
- resource_finder: Spree::Orders::FindComplete,
60
- resource_serializer: Spree::V2::Storefront::CartSerializer,
61
- collection_serializer: Spree::V2::Storefront::CartSerializer,
62
- collection_finder: Spree::Orders::FindComplete,
63
- collection_paginator: Spree::Shared::Paginate
64
- }
56
+ def collection_serializer
57
+ Spree::Api::Dependencies.storefront_cart_serializer.constantize
58
+ end
59
+
60
+ def resource_serializer
61
+ Spree::Api::Dependencies.storefront_cart_serializer.constantize
62
+ end
63
+
64
+ def collection_finder
65
+ Spree::Api::Dependencies.storefront_completed_order_finder.constantize
66
+ end
67
+
68
+ def resource_finder
69
+ Spree::Api::Dependencies.storefront_completed_order_finder.constantize
70
+ end
71
+
72
+ def collection_sorter
73
+ Spree::Api::Dependencies.storefront_order_sorter.constantize
74
+ end
75
+
76
+ def collection_paginator
77
+ Spree::Api::Dependencies.storefront_collection_paginator.constantize
65
78
  end
66
79
 
67
80
  def collection_options(collection)
@@ -16,15 +16,15 @@ module Spree
16
16
  end
17
17
 
18
18
  def serialize_resource(resource)
19
- dependencies[:resource_serializer].new(
19
+ resource_serializer.new(
20
20
  resource,
21
21
  include: resource_includes,
22
22
  fields: sparse_fields
23
23
  ).serializable_hash
24
24
  end
25
25
 
26
- def dependencies
27
- { resource_serializer: Spree::V2::Storefront::UserSerializer }
26
+ def resource_serializer
27
+ Spree::Api::Dependencies.storefront_user_serializer.constantize
28
28
  end
29
29
  end
30
30
  end
@@ -16,7 +16,7 @@ module Spree
16
16
  }
17
17
 
18
18
  order = spree_current_order if spree_current_order.present?
19
- order ||= dependencies[:create_cart].call(order_params).value
19
+ order ||= create_service.call(order_params).value
20
20
 
21
21
  render_serialized_payload(201) { serialize_order(order) }
22
22
  end
@@ -27,7 +27,7 @@ module Spree
27
27
  spree_authorize! :update, spree_current_order, order_token
28
28
  spree_authorize! :show, variant
29
29
 
30
- result = dependencies[:add_item_to_cart].call(
30
+ result = add_item_service.call(
31
31
  order: spree_current_order,
32
32
  variant: variant,
33
33
  quantity: params[:quantity],
@@ -40,7 +40,7 @@ module Spree
40
40
  def remove_line_item
41
41
  spree_authorize! :update, spree_current_order, order_token
42
42
 
43
- dependencies[:remove_item_from_cart].call(
43
+ remove_line_item_service.call(
44
44
  order: spree_current_order,
45
45
  line_item: line_item
46
46
  )
@@ -51,6 +51,8 @@ module Spree
51
51
  def empty
52
52
  spree_authorize! :update, spree_current_order, order_token
53
53
 
54
+ # TODO: we should extract this logic into service and let
55
+ # developers overwrite it
54
56
  spree_current_order.empty!
55
57
 
56
58
  render_serialized_payload { serialized_current_order }
@@ -61,7 +63,7 @@ module Spree
61
63
 
62
64
  spree_authorize! :update, spree_current_order, order_token
63
65
 
64
- result = dependencies[:set_item_quantity].call(order: spree_current_order, line_item: line_item, quantity: params[:quantity])
66
+ result = set_item_quantity_service.call(order: spree_current_order, line_item: line_item, quantity: params[:quantity])
65
67
 
66
68
  render_order(result)
67
69
  end
@@ -76,7 +78,7 @@ module Spree
76
78
  spree_authorize! :update, spree_current_order, order_token
77
79
 
78
80
  spree_current_order.coupon_code = params[:coupon_code]
79
- result = dependencies[:coupon_handler].new(spree_current_order).apply
81
+ result = coupon_handler.new(spree_current_order).apply
80
82
 
81
83
  if result.error.blank?
82
84
  render_serialized_payload { serialized_current_order }
@@ -88,7 +90,7 @@ module Spree
88
90
  def remove_coupon_code
89
91
  spree_authorize! :update, spree_current_order, order_token
90
92
 
91
- result = dependencies[:coupon_handler].new(spree_current_order).remove(params[:coupon_code])
93
+ result = coupon_handler.new(spree_current_order).remove(params[:coupon_code])
92
94
 
93
95
  if result.error.blank?
94
96
  render_serialized_payload { serialized_current_order }
@@ -99,15 +101,28 @@ module Spree
99
101
 
100
102
  private
101
103
 
102
- def dependencies
103
- {
104
- create_cart: Spree::Cart::Create,
105
- add_item_to_cart: Spree::Cart::AddItem,
106
- remove_item_from_cart: Spree::Cart::RemoveLineItem,
107
- cart_serializer: Spree::V2::Storefront::CartSerializer,
108
- set_item_quantity: Spree::Cart::SetQuantity,
109
- coupon_handler: Spree::PromotionHandler::Coupon
110
- }
104
+ def resource_serializer
105
+ Spree::Api::Dependencies.storefront_cart_serializer.constantize
106
+ end
107
+
108
+ def create_service
109
+ Spree::Api::Dependencies.storefront_cart_create_service.constantize
110
+ end
111
+
112
+ def add_item_service
113
+ Spree::Api::Dependencies.storefront_cart_add_item_service.constantize
114
+ end
115
+
116
+ def set_item_quantity_service
117
+ Spree::Api::Dependencies.storefront_cart_set_item_quantity_service.constantize
118
+ end
119
+
120
+ def remove_line_item_service
121
+ Spree::Api::Dependencies.storefront_cart_remove_line_item_service.constantize
122
+ end
123
+
124
+ def coupon_handler
125
+ Spree::Api::Dependencies.storefront_coupon_handler.constantize
111
126
  end
112
127
 
113
128
  def line_item
@@ -9,7 +9,7 @@ module Spree
9
9
  def next
10
10
  spree_authorize! :update, spree_current_order, order_token
11
11
 
12
- result = dependencies[:next_state_handler].call(order: spree_current_order)
12
+ result = next_service.call(order: spree_current_order)
13
13
 
14
14
  render_order(result)
15
15
  end
@@ -17,7 +17,7 @@ module Spree
17
17
  def advance
18
18
  spree_authorize! :update, spree_current_order, order_token
19
19
 
20
- result = dependencies[:advance_handler].call(order: spree_current_order)
20
+ result = advance_service.call(order: spree_current_order)
21
21
 
22
22
  render_order(result)
23
23
  end
@@ -25,7 +25,7 @@ module Spree
25
25
  def complete
26
26
  spree_authorize! :update, spree_current_order, order_token
27
27
 
28
- result = dependencies[:completer].call(order: spree_current_order)
28
+ result = complete_service.call(order: spree_current_order)
29
29
 
30
30
  render_order(result)
31
31
  end
@@ -33,10 +33,11 @@ module Spree
33
33
  def update
34
34
  spree_authorize! :update, spree_current_order, order_token
35
35
 
36
- result = dependencies[:updater].call(
36
+ result = update_service.call(
37
37
  order: spree_current_order,
38
38
  params: params,
39
- permitted_attributes: dependencies[:permitted_attributes],
39
+ # defined in https://github.com/spree/spree/blob/master/core/lib/spree/core/controller_helpers/strong_parameters.rb#L19
40
+ permitted_attributes: permitted_checkout_attributes,
40
41
  request_env: request.headers.env
41
42
  )
42
43
 
@@ -46,7 +47,7 @@ module Spree
46
47
  def add_store_credit
47
48
  spree_authorize! :update, spree_current_order, order_token
48
49
 
49
- result = dependencies[:add_store_credit_handler].call(
50
+ result = add_store_credit_service.call(
50
51
  order: spree_current_order,
51
52
  amount: params[:amount].try(:to_f)
52
53
  )
@@ -57,12 +58,12 @@ module Spree
57
58
  def remove_store_credit
58
59
  spree_authorize! :update, spree_current_order, order_token
59
60
 
60
- result = dependencies[:remove_store_credit_handler].call(order: spree_current_order)
61
+ result = remove_store_credit_service.call(order: spree_current_order)
61
62
  render_order(result)
62
63
  end
63
64
 
64
65
  def shipping_rates
65
- result = dependencies[:shipping_rates_getter].call(order: spree_current_order)
66
+ result = shipping_rates_service.call(order: spree_current_order)
66
67
 
67
68
  render_serialized_payload { serialize_shipping_rates(result.value) }
68
69
  end
@@ -73,29 +74,52 @@ module Spree
73
74
 
74
75
  private
75
76
 
76
- def dependencies
77
- {
78
- next_state_handler: Spree::Checkout::Next,
79
- advance_handler: Spree::Checkout::Advance,
80
- add_store_credit_handler: Spree::Checkout::AddStoreCredit,
81
- remove_store_credit_handler: Spree::Checkout::RemoveStoreCredit,
82
- completer: Spree::Checkout::Complete,
83
- updater: Spree::Checkout::Update,
84
- cart_serializer: Spree::V2::Storefront::CartSerializer,
85
- payment_methods_serializer: Spree::V2::Storefront::PaymentMethodSerializer,
86
- shipping_rates_getter: Spree::Checkout::GetShippingRates,
87
- shipping_rates_serializer: Spree::V2::Storefront::ShipmentSerializer,
88
- # defined in https://github.com/spree/spree/blob/master/core/lib/spree/core/controller_helpers/strong_parameters.rb#L19
89
- permitted_attributes: permitted_checkout_attributes
90
- }
77
+ def resource_serializer
78
+ Spree::Api::Dependencies.storefront_cart_serializer.constantize
79
+ end
80
+
81
+ def next_service
82
+ Spree::Api::Dependencies.storefront_checkout_next_service.constantize
83
+ end
84
+
85
+ def advance_service
86
+ Spree::Api::Dependencies.storefront_checkout_advance_service.constantize
87
+ end
88
+
89
+ def add_store_credit_service
90
+ Spree::Api::Dependencies.storefront_checkout_add_store_credit_service.constantize
91
+ end
92
+
93
+ def remove_store_credit_service
94
+ Spree::Api::Dependencies.storefront_checkout_remove_store_credit_service.constantize
95
+ end
96
+
97
+ def complete_service
98
+ Spree::Api::Dependencies.storefront_checkout_complete_service.constantize
99
+ end
100
+
101
+ def update_service
102
+ Spree::Api::Dependencies.storefront_checkout_update_service.constantize
103
+ end
104
+
105
+ def payment_methods_serializer
106
+ Spree::Api::Dependencies.storefront_payment_method_serializer.constantize
107
+ end
108
+
109
+ def shipping_rates_service
110
+ Spree::Api::Dependencies.storefront_checkout_get_shipping_rates_service.constantize
111
+ end
112
+
113
+ def shipping_rates_serializer
114
+ Spree::Api::Dependencies.storefront_shipment_serializer.constantize
91
115
  end
92
116
 
93
117
  def serialize_payment_methods(payment_methods)
94
- dependencies[:payment_methods_serializer].new(payment_methods).serializable_hash
118
+ payment_methods_serializer.new(payment_methods).serializable_hash
95
119
  end
96
120
 
97
121
  def serialize_shipping_rates(shipments)
98
- dependencies[:shipping_rates_serializer].new(
122
+ shipping_rates_serializer.new(
99
123
  shipments,
100
124
  include: [:shipping_rates],
101
125
  params: { show_rates: true }
@@ -16,11 +16,11 @@ module Spree
16
16
  private
17
17
 
18
18
  def serialize_collection(collection)
19
- dependencies[:collection_serializer].new(collection).serializable_hash
19
+ collection_serializer.new(collection).serializable_hash
20
20
  end
21
21
 
22
22
  def serialize_resource(resource)
23
- dependencies[:resource_serializer].new(
23
+ resource_serializer.new(
24
24
  resource,
25
25
  include: resource_includes,
26
26
  fields: sparse_fields,
@@ -29,7 +29,7 @@ module Spree
29
29
  end
30
30
 
31
31
  def collection
32
- dependencies[:collection_finder].new(scope, params).call
32
+ collection_finder.new(scope, params).call
33
33
  end
34
34
 
35
35
  def resource
@@ -39,12 +39,16 @@ module Spree
39
39
  scope.find_by(iso3: params[:iso]&.upcase)
40
40
  end
41
41
 
42
- def dependencies
43
- {
44
- collection_serializer: Spree::V2::Storefront::CountrySerializer,
45
- resource_serializer: Spree::V2::Storefront::CountrySerializer,
46
- collection_finder: Spree::Countries::Find
47
- }
42
+ def resource_serializer
43
+ Spree::Api::Dependencies.storefront_country_serializer.constantize
44
+ end
45
+
46
+ def collection_serializer
47
+ Spree::Api::Dependencies.storefront_country_serializer.constantize
48
+ end
49
+
50
+ def collection_finder
51
+ Spree::Api::Dependencies.storefront_country_finder.constantize
48
52
  end
49
53
 
50
54
  def scope
@@ -16,14 +16,14 @@ module Spree
16
16
  private
17
17
 
18
18
  def serialize_collection(collection)
19
- dependencies[:collection_serializer].new(
19
+ collection_serializer.new(
20
20
  collection,
21
21
  collection_options(collection)
22
22
  ).serializable_hash
23
23
  end
24
24
 
25
25
  def serialize_resource(resource)
26
- dependencies[:resource_serializer].new(
26
+ resource_serializer.new(
27
27
  resource,
28
28
  include: resource_includes,
29
29
  fields: sparse_fields
@@ -31,29 +31,35 @@ module Spree
31
31
  end
32
32
 
33
33
  def paginated_collection
34
- dependencies[:collection_paginator].new(sorted_collection, params).call
34
+ collection_paginator.new(sorted_collection, params).call
35
35
  end
36
36
 
37
37
  def sorted_collection
38
- dependencies[:collection_sorter].new(collection, params, current_currency).call
38
+ collection_sorter.new(collection, params, current_currency).call
39
39
  end
40
40
 
41
41
  def collection
42
- dependencies[:collection_finder].new(scope: scope, params: params, current_currency: current_currency).execute
42
+ collection_finder.new(scope: scope, params: params, current_currency: current_currency).execute
43
43
  end
44
44
 
45
45
  def resource
46
46
  scope.find_by(slug: params[:id]) || scope.find(params[:id])
47
47
  end
48
48
 
49
- def dependencies
50
- {
51
- collection_sorter: Spree::Products::Sort,
52
- collection_finder: Spree::Products::Find,
53
- collection_paginator: Spree::Shared::Paginate,
54
- collection_serializer: Spree::V2::Storefront::ProductSerializer,
55
- resource_serializer: Spree::V2::Storefront::ProductSerializer
56
- }
49
+ def collection_sorter
50
+ Spree::Api::Dependencies.storefront_products_sorter.constantize
51
+ end
52
+
53
+ def collection_finder
54
+ Spree::Api::Dependencies.storefront_products_finder.constantize
55
+ end
56
+
57
+ def collection_serializer
58
+ Spree::Api::Dependencies.storefront_product_serializer.constantize
59
+ end
60
+
61
+ def resource_serializer
62
+ Spree::Api::Dependencies.storefront_product_serializer.constantize
57
63
  end
58
64
 
59
65
  def collection_options(collection)
@@ -16,27 +16,30 @@ module Spree
16
16
  private
17
17
 
18
18
  def serialize_collection(collection)
19
- dependencies[:collection_serializer].new(
19
+ collection_serializer.new(
20
20
  collection,
21
21
  collection_options(collection)
22
22
  ).serializable_hash
23
23
  end
24
24
 
25
25
  def serialize_resource(resource)
26
- dependencies[:resource_serializer].new(
26
+ resource_serializer.new(
27
27
  resource,
28
28
  include: resource_includes,
29
29
  fields: sparse_fields
30
30
  ).serializable_hash
31
31
  end
32
32
 
33
- def dependencies
34
- {
35
- collection_finder: Spree::Taxons::Find,
36
- collection_paginator: Spree::Shared::Paginate,
37
- collection_serializer: Spree::V2::Storefront::TaxonSerializer,
38
- resource_serializer: Spree::V2::Storefront::TaxonSerializer
39
- }
33
+ def collection_serializer
34
+ Spree::Api::Dependencies.storefront_taxon_serializer.constantize
35
+ end
36
+
37
+ def resource_serializer
38
+ Spree::Api::Dependencies.storefront_taxon_serializer.constantize
39
+ end
40
+
41
+ def collection_finder
42
+ Spree::Api::Dependencies.storefront_taxon_finder.constantize
40
43
  end
41
44
 
42
45
  def collection_options(collection)
@@ -49,11 +52,11 @@ module Spree
49
52
  end
50
53
 
51
54
  def paginated_collection
52
- dependencies[:collection_paginator].new(collection, params).call
55
+ collection_paginator.new(collection, params).call
53
56
  end
54
57
 
55
58
  def collection
56
- dependencies[:collection_finder].new(scope: scope, params: params).execute
59
+ collection_finder.new(scope: scope, params: params).execute
57
60
  end
58
61
 
59
62
  def resource
@@ -0,0 +1,77 @@
1
+ module Spree
2
+ class ApiDependencies
3
+ include Spree::DependenciesHelper
4
+
5
+ INJECTION_POINTS = [
6
+ :storefront_cart_create_service, :storefront_cart_add_item_service, :storefront_cart_remove_line_item_service,
7
+ :storefront_cart_remove_item_service, :storefront_cart_set_item_quantity_service, :storefront_cart_recalculate_service,
8
+ :storefront_cart_update, :storefront_coupon_handler, :storefront_checkout_next_service, :storefront_checkout_advance_service,
9
+ :storefront_checkout_update_service, :storefront_checkout_complete_service, :storefront_checkout_add_store_credit_service,
10
+ :storefront_checkout_remove_store_credit_service, :storefront_checkout_get_shipping_rates_service,
11
+ :storefront_cart_compare_line_items_service, :storefront_cart_serializer, :storefront_credit_card_serializer,
12
+ :storefront_credit_card_finder, :storefront_shipment_serializer, :storefront_payment_method_serializer, :storefront_country_finder,
13
+ :storefront_country_serializer, :storefront_current_order_finder, :storefront_completed_order_finder, :storefront_order_sorter,
14
+ :storefront_collection_paginator, :storefront_user_serializer, :storefront_products_sorter, :storefront_products_finder,
15
+ :storefront_product_serializer, :storefront_taxon_serializer, :storefront_taxon_finder, :storefront_find_by_variant_finder,
16
+ :storefront_cart_update_service
17
+ ].freeze
18
+
19
+ attr_accessor *INJECTION_POINTS
20
+
21
+ def initialize
22
+ set_storefront_defaults
23
+ end
24
+
25
+ private
26
+
27
+ def set_storefront_defaults
28
+ # cart services
29
+ @storefront_cart_create_service = Spree::Dependencies.cart_create_service
30
+ @storefront_cart_add_item_service = Spree::Dependencies.cart_add_item_service
31
+ @storefront_cart_compare_line_items_service = Spree::Dependencies.cart_compare_line_items_service
32
+ @storefront_cart_update_service = Spree::Dependencies.cart_update_service
33
+ @storefront_cart_remove_line_item_service = Spree::Dependencies.cart_remove_line_item_service
34
+ @storefront_cart_remove_item_service = Spree::Dependencies.cart_remove_item_service
35
+ @storefront_cart_set_item_quantity_service = Spree::Dependencies.cart_set_item_quantity_service
36
+ @storefront_cart_recalculate_service = Spree::Dependencies.cart_recalculate_service
37
+
38
+ # coupon code handler
39
+ @storefront_coupon_handler = Spree::Dependencies.coupon_handler
40
+
41
+ # checkout services
42
+ @storefront_checkout_next_service = Spree::Dependencies.checkout_next_service
43
+ @storefront_checkout_advance_service = Spree::Dependencies.checkout_advance_service
44
+ @storefront_checkout_update_service = Spree::Dependencies.checkout_update_service
45
+ @storefront_checkout_complete_service = Spree::Dependencies.checkout_complete_service
46
+ @storefront_checkout_add_store_credit_service = Spree::Dependencies.checkout_add_store_credit_service
47
+ @storefront_checkout_remove_store_credit_service = Spree::Dependencies.checkout_remove_store_credit_service
48
+ @storefront_checkout_get_shipping_rates_service = Spree::Dependencies.checkout_get_shipping_rates_service
49
+
50
+ # serializers
51
+ @storefront_cart_serializer = 'Spree::V2::Storefront::CartSerializer'
52
+ @storefront_credit_card_serializer = 'Spree::V2::Storefront::CreditCardSerializer'
53
+ @storefront_country_serializer = 'Spree::V2::Storefront::CountrySerializer'
54
+ @storefront_user_serializer = 'Spree::V2::Storefront::UserSerializer'
55
+ @storefront_shipment_serializer = 'Spree::V2::Storefront::ShipmentSerializer'
56
+ @storefront_taxon_serializer = 'Spree::V2::Storefront::TaxonSerializer'
57
+ @storefront_payment_method_serializer = 'Spree::V2::Storefront::PaymentMethodSerializer'
58
+ @storefront_product_serializer = 'Spree::V2::Storefront::ProductSerializer'
59
+
60
+ # sorters
61
+ @storefront_order_sorter = Spree::Dependencies.order_sorter
62
+ @storefront_products_sorter = Spree::Dependencies.products_sorter
63
+
64
+ # paginators
65
+ @storefront_collection_paginator = Spree::Dependencies.collection_paginator
66
+
67
+ # finders
68
+ @storefront_country_finder = Spree::Dependencies.country_finder
69
+ @storefront_current_order_finder = Spree::Dependencies.current_order_finder
70
+ @storefront_completed_order_finder = Spree::Dependencies.completed_order_finder
71
+ @storefront_credit_card_finder = Spree::Dependencies.credit_card_finder
72
+ @storefront_find_by_variant_finder = Spree::Dependencies.line_item_by_variant_finder
73
+ @storefront_products_finder = Spree::Dependencies.products_finder
74
+ @storefront_taxon_finder = Spree::Dependencies.taxon_finder
75
+ end
76
+ end
77
+ end
@@ -37,6 +37,7 @@ module Spree
37
37
 
38
38
  initializer 'spree.api.environment', before: :load_config_initializers do |_app|
39
39
  Spree::Api::Config = Spree::ApiConfiguration.new
40
+ Spree::Api::Dependencies = Spree::ApiDependencies.new
40
41
  end
41
42
 
42
43
  initializer 'spree.api.checking_migrations' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.rc2
4
+ version: 3.7.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-22 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-rspec
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.7.0.rc2
33
+ version: 3.7.0.rc3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.7.0.rc2
40
+ version: 3.7.0.rc3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rabl
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,7 @@ files:
158
158
  - app/models/doorkeeper/access_token_decorator.rb
159
159
  - app/models/doorkeeper/application_decorator.rb
160
160
  - app/models/spree/api_configuration.rb
161
+ - app/models/spree/api_dependencies.rb
161
162
  - app/serializers/spree/v2/storefront/address_serializer.rb
162
163
  - app/serializers/spree/v2/storefront/base_serializer.rb
163
164
  - app/serializers/spree/v2/storefront/cart_serializer.rb
@@ -323,8 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
324
  - !ruby/object:Gem::Version
324
325
  version: 1.3.1
325
326
  requirements: []
326
- rubyforge_project:
327
- rubygems_version: 2.7.8
327
+ rubygems_version: 3.0.2
328
328
  signing_key:
329
329
  specification_version: 4
330
330
  summary: Spree's API