spree_api 4.2.0.rc1 → 4.2.0
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 +4 -4
- data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +7 -7
- data/app/controllers/spree/api/base_controller.rb +10 -2
- data/app/controllers/spree/api/v1/shipments_controller.rb +16 -6
- data/app/controllers/spree/api/v1/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +21 -4
- data/app/controllers/spree/api/v2/resource_controller.rb +59 -0
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +3 -11
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +7 -15
- data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +7 -26
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +1 -5
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -16
- data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +2 -6
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +4 -14
- data/app/controllers/spree/api/v2/storefront/stores_controller.rb +2 -6
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +3 -13
- data/app/helpers/spree/api/api_helpers.rb +1 -1
- data/app/helpers/spree/api/v2/display_money_helper.rb +43 -0
- data/app/models/spree/api_configuration.rb +1 -0
- data/app/models/spree/api_dependencies.rb +8 -3
- data/app/serializers/spree/v2/storefront/address_serializer.rb +7 -2
- data/app/serializers/spree/v2/storefront/base_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cart_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/country_serializer.rb +6 -0
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +7 -2
- data/app/serializers/spree/v2/storefront/product_serializer.rb +38 -7
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/store_credit_category_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +11 -3
- data/app/serializers/spree/v2/storefront/user_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +34 -5
- data/app/services/spree/api/error_handler.rb +40 -0
- data/config/initializers/doorkeeper.rb +10 -1
- data/config/locales/en.yml +1 -1
- data/docs/oauth/index.yml +78 -15
- data/docs/v2/storefront/index.yaml +3232 -663
- data/lib/spree/api/testing_support/v2/current_order.rb +2 -0
- data/lib/spree_api.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa0ba5ffcc873cf68159260e0b7f52879f39f54f7140887a438c73f1257293d2
|
4
|
+
data.tar.gz: 1f05304db222d36a1f31d563ea5a071a01cfe7eb80fa4c13a002b6a4dd6775f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d83abd3762d05c58b37e8290d0fddc8ead28edc15ad3dd1267915ed2abb234399a36071a8250d4d7a3e08a0871e5e438acff6a28a67d2512460ec718c1785dd
|
7
|
+
data.tar.gz: 41eee02e45c3491b25333eecda173b23a520e0595ba39ef4c38ad1eb7d356d4c206ee7f16d19fd927f5e291475e3a40f6a785a634f0c1055f29cf60ad1e82ea8
|
@@ -34,16 +34,16 @@ module Spree
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def serialized_current_order
|
38
|
+
serialize_resource(spree_current_order)
|
39
39
|
end
|
40
40
|
|
41
41
|
def serialize_order(order)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
|
43
|
+
`OrderConcern#serialize_order` is deprecated and will be removed in Spree 5.0.
|
44
|
+
Please use `serializer_resource` method
|
45
|
+
DEPRECATION
|
46
|
+
serialize_resource(order)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -6,6 +6,8 @@ module Spree
|
|
6
6
|
include Spree::Api::ControllerSetup
|
7
7
|
include Spree::Core::ControllerHelpers::Store
|
8
8
|
include Spree::Core::ControllerHelpers::StrongParameters
|
9
|
+
include Spree::Core::ControllerHelpers::Locale
|
10
|
+
include Spree::Core::ControllerHelpers::Currency
|
9
11
|
|
10
12
|
attr_accessor :current_api_user
|
11
13
|
|
@@ -81,10 +83,16 @@ module Spree
|
|
81
83
|
end
|
82
84
|
|
83
85
|
def error_during_processing(exception)
|
84
|
-
|
86
|
+
message = if exception.respond_to?(:original_message)
|
87
|
+
exception.original_message
|
88
|
+
else
|
89
|
+
exception.message
|
90
|
+
end
|
91
|
+
|
92
|
+
Rails.logger.error message
|
85
93
|
Rails.logger.error exception.backtrace.join("\n")
|
86
94
|
|
87
|
-
unprocessable_entity(
|
95
|
+
unprocessable_entity(message)
|
88
96
|
end
|
89
97
|
|
90
98
|
def unprocessable_entity(message)
|
@@ -92,12 +92,17 @@ module Spree
|
|
92
92
|
@stock_location = Spree::StockLocation.find(params[:stock_location_id])
|
93
93
|
|
94
94
|
unless @quantity > 0
|
95
|
-
unprocessable_entity("#{Spree.t(:
|
95
|
+
unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n #{Spree.t(:negative_quantity, scope: 'api')}")
|
96
96
|
return
|
97
97
|
end
|
98
98
|
|
99
|
-
@original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
|
100
|
-
|
99
|
+
transfer = @original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
|
100
|
+
if transfer.valid?
|
101
|
+
transfer.run!
|
102
|
+
render json: { message: Spree.t(:shipment_transfer_success) }, status: 201
|
103
|
+
else
|
104
|
+
render json: { message: transfer.errors.full_messages.to_sentence }, status: 422
|
105
|
+
end
|
101
106
|
end
|
102
107
|
|
103
108
|
def transfer_to_shipment
|
@@ -113,10 +118,15 @@ module Spree
|
|
113
118
|
end
|
114
119
|
|
115
120
|
if error
|
116
|
-
unprocessable_entity("#{Spree.t(:
|
121
|
+
unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{error}")
|
117
122
|
else
|
118
|
-
@original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
119
|
-
|
123
|
+
transfer = @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
|
124
|
+
if transfer.valid?
|
125
|
+
transfer.run!
|
126
|
+
render json: { message: Spree.t(:shipment_transfer_success) }, status: 201
|
127
|
+
else
|
128
|
+
render json: { message: transfer.errors.full_messages }, status: 422
|
129
|
+
end
|
120
130
|
end
|
121
131
|
end
|
122
132
|
|
@@ -37,7 +37,7 @@ module Spree
|
|
37
37
|
invalid_resource!(@taxon) and return
|
38
38
|
end
|
39
39
|
|
40
|
-
@taxon.parent_id = taxonomy.
|
40
|
+
@taxon.parent_id = taxonomy.root_id unless params[:taxon][:parent_id]
|
41
41
|
|
42
42
|
if @taxon.save
|
43
43
|
respond_with(@taxon, status: 201, default_template: :show)
|
@@ -5,26 +5,31 @@ module Spree
|
|
5
5
|
include CanCan::ControllerAdditions
|
6
6
|
include Spree::Core::ControllerHelpers::StrongParameters
|
7
7
|
include Spree::Core::ControllerHelpers::Store
|
8
|
+
include Spree::Core::ControllerHelpers::Locale
|
9
|
+
include Spree::Core::ControllerHelpers::Currency
|
8
10
|
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
9
11
|
rescue_from CanCan::AccessDenied, with: :access_denied
|
10
12
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
13
|
+
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
14
|
+
rescue_from ArgumentError, with: :error_during_processing
|
11
15
|
|
12
16
|
def content_type
|
13
17
|
Spree::Api::Config[:api_v2_content_type]
|
14
18
|
end
|
15
19
|
|
16
|
-
|
20
|
+
protected
|
17
21
|
|
18
22
|
def serialize_collection(collection)
|
19
23
|
collection_serializer.new(
|
20
24
|
collection,
|
21
|
-
collection_options(collection)
|
25
|
+
collection_options(collection).merge(params: serializer_params)
|
22
26
|
).serializable_hash
|
23
27
|
end
|
24
28
|
|
25
29
|
def serialize_resource(resource)
|
26
30
|
resource_serializer.new(
|
27
31
|
resource,
|
32
|
+
params: serializer_params,
|
28
33
|
include: resource_includes,
|
29
34
|
fields: sparse_fields
|
30
35
|
).serializable_hash
|
@@ -40,8 +45,6 @@ module Spree
|
|
40
45
|
|
41
46
|
def render_serialized_payload(status = 200)
|
42
47
|
render json: yield, status: status, content_type: content_type
|
43
|
-
rescue ArgumentError => exception
|
44
|
-
render_error_payload(exception.message, 400)
|
45
48
|
end
|
46
49
|
|
47
50
|
def render_error_payload(error, status = 422)
|
@@ -107,6 +110,10 @@ module Spree
|
|
107
110
|
fields.presence
|
108
111
|
end
|
109
112
|
|
113
|
+
def serializer_params
|
114
|
+
{ currency: current_currency, store: current_store, user: spree_current_user }
|
115
|
+
end
|
116
|
+
|
110
117
|
def record_not_found
|
111
118
|
render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
|
112
119
|
end
|
@@ -118,6 +125,16 @@ module Spree
|
|
118
125
|
def gateway_error(exception)
|
119
126
|
render_error_payload(exception.message)
|
120
127
|
end
|
128
|
+
|
129
|
+
def error_during_processing(exception)
|
130
|
+
result = error_handler.call(exception: exception, opts: { user: spree_current_user })
|
131
|
+
|
132
|
+
render_error_payload(result.value[:message], 400)
|
133
|
+
end
|
134
|
+
|
135
|
+
def error_handler
|
136
|
+
Spree::Api::Dependencies.error_handler.constantize
|
137
|
+
end
|
121
138
|
end
|
122
139
|
end
|
123
140
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class ResourceController < ::Spree::Api::V2::BaseController
|
5
|
+
include Spree::Api::V2::CollectionOptionsHelpers
|
6
|
+
|
7
|
+
def index
|
8
|
+
render_serialized_payload { serialize_collection(paginated_collection) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
render_serialized_payload { serialize_resource(resource) }
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def sorted_collection
|
18
|
+
collection_sorter.new(collection, params, allowed_sort_attributes).call
|
19
|
+
end
|
20
|
+
|
21
|
+
def allowed_sort_attributes
|
22
|
+
default_sort_atributes
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_sort_atributes
|
26
|
+
[:id, :updated_at, :created_at]
|
27
|
+
end
|
28
|
+
|
29
|
+
def scope
|
30
|
+
model_class.accessible_by(current_ability, :show).includes(scope_includes)
|
31
|
+
end
|
32
|
+
|
33
|
+
def scope_includes
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
def resource
|
38
|
+
@resource ||= if defined?(resource_finder)
|
39
|
+
resource_finder.new(scope: scope, params: params).execute
|
40
|
+
else
|
41
|
+
scope.find(params[:id])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def collection
|
46
|
+
@collection ||= if defined?(collection_finder)
|
47
|
+
collection_finder.new(scope: scope, params: params).execute
|
48
|
+
else
|
49
|
+
scope
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def collection_sorter
|
54
|
+
Spree::Api::Dependencies.storefront_collection_sorter.constantize
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -3,13 +3,9 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
5
|
module Account
|
6
|
-
class AddressesController < ::Spree::Api::V2::
|
6
|
+
class AddressesController < ::Spree::Api::V2::ResourceController
|
7
7
|
before_action :require_spree_current_user
|
8
8
|
|
9
|
-
def index
|
10
|
-
render_serialized_payload { serialize_collection(collection) }
|
11
|
-
end
|
12
|
-
|
13
9
|
def create
|
14
10
|
result = create_service.call(user: spree_current_user, address_params: address_params)
|
15
11
|
render_result(result)
|
@@ -26,12 +22,8 @@ module Spree
|
|
26
22
|
collection_finder.new(scope: scope, params: params).execute
|
27
23
|
end
|
28
24
|
|
29
|
-
def
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def scope
|
34
|
-
spree_current_user.addresses
|
25
|
+
def model_class
|
26
|
+
Spree::Address
|
35
27
|
end
|
36
28
|
|
37
29
|
def collection_finder
|
@@ -3,27 +3,23 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
5
|
module Account
|
6
|
-
class CreditCardsController < ::Spree::Api::V2::
|
6
|
+
class CreditCardsController < ::Spree::Api::V2::ResourceController
|
7
7
|
before_action :require_spree_current_user
|
8
8
|
|
9
|
-
def index
|
10
|
-
render_serialized_payload { serialize_collection(resource) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def show
|
14
|
-
render_serialized_payload { serialize_resource(resource) }
|
15
|
-
end
|
16
|
-
|
17
9
|
private
|
18
10
|
|
19
|
-
def
|
20
|
-
|
11
|
+
def model_class
|
12
|
+
Spree::CreditCard
|
21
13
|
end
|
22
14
|
|
23
15
|
def collection_serializer
|
24
16
|
Spree::Api::Dependencies.storefront_credit_card_serializer.constantize
|
25
17
|
end
|
26
18
|
|
19
|
+
def collection_finder
|
20
|
+
Spree::Api::Dependencies.storefront_credit_card_finder.constantize
|
21
|
+
end
|
22
|
+
|
27
23
|
def resource_serializer
|
28
24
|
Spree::Api::Dependencies.storefront_credit_card_serializer.constantize
|
29
25
|
end
|
@@ -39,10 +35,6 @@ module Spree
|
|
39
35
|
fields: sparse_fields
|
40
36
|
).serializable_hash
|
41
37
|
end
|
42
|
-
|
43
|
-
def scope
|
44
|
-
spree_current_user.credit_cards.accessible_by(current_ability, :show)
|
45
|
-
end
|
46
38
|
end
|
47
39
|
end
|
48
40
|
end
|
@@ -3,26 +3,11 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
5
|
module Account
|
6
|
-
class OrdersController < ::Spree::Api::V2::
|
7
|
-
include Spree::Api::V2::CollectionOptionsHelpers
|
6
|
+
class OrdersController < ::Spree::Api::V2::ResourceController
|
8
7
|
before_action :require_spree_current_user
|
9
8
|
|
10
|
-
def index
|
11
|
-
render_serialized_payload { serialize_collection(paginated_collection) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def show
|
15
|
-
spree_authorize! :show, resource
|
16
|
-
|
17
|
-
render_serialized_payload { serialize_resource(resource) }
|
18
|
-
end
|
19
|
-
|
20
9
|
private
|
21
10
|
|
22
|
-
def sorted_collection
|
23
|
-
collection_sorter.new(collection, params).call
|
24
|
-
end
|
25
|
-
|
26
11
|
def collection
|
27
12
|
collection_finder.new(user: spree_current_user).execute
|
28
13
|
end
|
@@ -34,12 +19,16 @@ module Spree
|
|
34
19
|
resource
|
35
20
|
end
|
36
21
|
|
22
|
+
def allowed_sort_attributes
|
23
|
+
super << :completed_at
|
24
|
+
end
|
25
|
+
|
37
26
|
def collection_serializer
|
38
|
-
Spree::Api::Dependencies.
|
27
|
+
Spree::Api::Dependencies.storefront_order_serializer.constantize
|
39
28
|
end
|
40
29
|
|
41
30
|
def resource_serializer
|
42
|
-
Spree::Api::Dependencies.
|
31
|
+
Spree::Api::Dependencies.storefront_order_serializer.constantize
|
43
32
|
end
|
44
33
|
|
45
34
|
def collection_finder
|
@@ -49,14 +38,6 @@ module Spree
|
|
49
38
|
def resource_finder
|
50
39
|
Spree::Api::Dependencies.storefront_completed_order_finder.constantize
|
51
40
|
end
|
52
|
-
|
53
|
-
def collection_sorter
|
54
|
-
Spree::Api::Dependencies.storefront_order_sorter.constantize
|
55
|
-
end
|
56
|
-
|
57
|
-
def collection_paginator
|
58
|
-
Spree::Api::Dependencies.storefront_collection_paginator.constantize
|
59
|
-
end
|
60
41
|
end
|
61
42
|
end
|
62
43
|
end
|
@@ -2,13 +2,9 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class AccountController < ::Spree::Api::V2::
|
5
|
+
class AccountController < ::Spree::Api::V2::ResourceController
|
6
6
|
before_action :require_spree_current_user
|
7
7
|
|
8
|
-
def show
|
9
|
-
render_serialized_payload { serialize_resource(resource) }
|
10
|
-
end
|
11
|
-
|
12
8
|
private
|
13
9
|
|
14
10
|
def resource
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
order = spree_current_order if spree_current_order.present?
|
20
20
|
order ||= create_service.call(order_params).value
|
21
21
|
|
22
|
-
render_serialized_payload(201) {
|
22
|
+
render_serialized_payload(201) { serialize_resource(order) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def add_item
|
@@ -2,17 +2,7 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
|
-
class CountriesController < ::Spree::Api::V2::
|
6
|
-
include Spree::Api::V2::CollectionOptionsHelpers
|
7
|
-
|
8
|
-
def index
|
9
|
-
render_serialized_payload { serialize_collection(collection) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
render_serialized_payload { serialize_resource(resource) }
|
14
|
-
end
|
15
|
-
|
5
|
+
class CountriesController < ::Spree::Api::V2::ResourceController
|
16
6
|
private
|
17
7
|
|
18
8
|
def serialize_collection(collection)
|
@@ -24,12 +14,15 @@ module Spree
|
|
24
14
|
resource,
|
25
15
|
include: resource_includes,
|
26
16
|
fields: sparse_fields,
|
27
|
-
params:
|
17
|
+
params: resource_serializer_params
|
28
18
|
).serializable_hash
|
29
19
|
end
|
30
20
|
|
31
|
-
def
|
32
|
-
|
21
|
+
def resource_serializer_params
|
22
|
+
{
|
23
|
+
include_states: true,
|
24
|
+
current_store: current_store
|
25
|
+
}
|
33
26
|
end
|
34
27
|
|
35
28
|
def resource
|
@@ -52,8 +45,8 @@ module Spree
|
|
52
45
|
Spree::Api::Dependencies.storefront_country_finder.constantize
|
53
46
|
end
|
54
47
|
|
55
|
-
def
|
56
|
-
Spree::Country
|
48
|
+
def model_class
|
49
|
+
Spree::Country
|
57
50
|
end
|
58
51
|
end
|
59
52
|
end
|