spree_api 4.1.13 → 4.2.0.rc4
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 +4 -0
- data/app/controllers/spree/api/base_controller.rb +9 -5
- data/app/controllers/spree/api/errors_controller.rb +1 -1
- data/app/controllers/spree/api/v1/shipments_controller.rb +16 -6
- data/app/controllers/spree/api/v1/taxons_controller.rb +6 -1
- data/app/controllers/spree/api/v1/users_controller.rb +35 -9
- data/app/controllers/spree/api/v2/base_controller.rb +6 -25
- data/app/controllers/spree/api/v2/resource_controller.rb +82 -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 +5 -24
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +1 -5
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -16
- data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -5
- 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 +4 -14
- data/app/helpers/spree/api/api_helpers.rb +4 -3
- data/app/models/spree/api_dependencies.rb +4 -2
- data/app/serializers/spree/v2/storefront/address_serializer.rb +8 -3
- data/app/serializers/spree/v2/storefront/base_serializer.rb +1 -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/product_property_serializer.rb +7 -2
- data/app/serializers/spree/v2/storefront/product_serializer.rb +17 -6
- 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_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 +13 -5
- data/app/views/spree/api/v1/products/show.rabl +4 -0
- data/config/locales/en.yml +1 -1
- data/docs/oauth/index.yml +78 -15
- data/docs/v2/storefront/index.yaml +3409 -672
- data/lib/spree/api/controller_setup.rb +0 -1
- data/lib/spree_api.rb +1 -1
- data/spree_api.gemspec +2 -2
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c7b8ebf1a65cf7fb7063b4811c8d6226298c6435b5fdb9a60fd0c9a0579567d
|
4
|
+
data.tar.gz: 33ab903daaec69fdcb23340146c6e78be7dc64dbe760d2885353518d977887d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f108ec0840bcfdf1aa5f15a8cf7f1de53fc7420bc0d0fc93072786ce139f60afcf5506470dca75c32cfac4b70221b4a9858e8b0a528b643e3f411c892cd46c9
|
7
|
+
data.tar.gz: 75d052059dda3df22fd17236878a14b9ca9a07da5bb287b0df03c11ea347a02abadabf75e2f7f7da950cd9e8bfdb56e96294d0a14ec46049797a63a69da58711
|
@@ -34,6 +34,10 @@ module Spree
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
+
def supported_currencies
|
38
|
+
current_store.supported_currencies_list
|
39
|
+
end
|
40
|
+
|
37
41
|
def serialize_order(order)
|
38
42
|
resource_serializer.new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
|
39
43
|
end
|
@@ -2,9 +2,7 @@ require_dependency 'spree/api/controller_setup'
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
module Api
|
5
|
-
class BaseController < ActionController::
|
6
|
-
protect_from_forgery unless: -> { request.format.json? || request.format.xml? }
|
7
|
-
|
5
|
+
class BaseController < ActionController::API
|
8
6
|
include Spree::Api::ControllerSetup
|
9
7
|
include Spree::Core::ControllerHelpers::Store
|
10
8
|
include Spree::Core::ControllerHelpers::StrongParameters
|
@@ -83,10 +81,16 @@ module Spree
|
|
83
81
|
end
|
84
82
|
|
85
83
|
def error_during_processing(exception)
|
86
|
-
|
84
|
+
message = if exception.respond_to?(:original_message)
|
85
|
+
exception.original_message
|
86
|
+
else
|
87
|
+
exception.message
|
88
|
+
end
|
89
|
+
|
90
|
+
Rails.logger.error message
|
87
91
|
Rails.logger.error exception.backtrace.join("\n")
|
88
92
|
|
89
|
-
unprocessable_entity(
|
93
|
+
unprocessable_entity(message)
|
90
94
|
end
|
91
95
|
|
92
96
|
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
|
|
@@ -74,7 +74,12 @@ module Spree
|
|
74
74
|
|
75
75
|
def taxonomy
|
76
76
|
if params[:taxonomy_id].present?
|
77
|
-
@taxonomy ||=
|
77
|
+
@taxonomy ||=
|
78
|
+
if defined?(SpreeGlobalize)
|
79
|
+
Spree::Taxonomy.includes(:translations, taxons: [:translations]).accessible_by(current_ability, :show).find(params[:taxonomy_id])
|
80
|
+
else
|
81
|
+
Spree::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id])
|
82
|
+
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
@@ -5,22 +5,48 @@ module Spree
|
|
5
5
|
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
6
6
|
|
7
7
|
def index
|
8
|
-
|
8
|
+
users
|
9
9
|
|
10
10
|
if params[:ids]
|
11
|
-
|
12
|
-
elsif params
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
users_with_addresses_ids = (users_with_ship_address.ids + users_with_bill_address.ids).compact.uniq
|
17
|
-
@users = @users.with_email_or_addresses_ids(params[:q][:email_start], users_with_addresses_ids)
|
11
|
+
load_users_by_ids
|
12
|
+
elsif params.dig(:q, :ship_address_firstname_start)
|
13
|
+
load_users_by_address
|
14
|
+
elsif params.dig(:q, :email_start)
|
15
|
+
load_users_by_email
|
18
16
|
end
|
19
17
|
|
18
|
+
prepare_index_response
|
19
|
+
respond_with(@users)
|
20
|
+
end
|
21
|
+
|
22
|
+
def users
|
23
|
+
@users ||= Spree.user_class.accessible_by(current_ability, :show)
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_users_by_ids
|
27
|
+
@users = @users.where(id: params[:ids])
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_users_by_address
|
31
|
+
address_params = params[:q][:ship_address_firstname_start] ||
|
32
|
+
params[:q][:ship_address_lastname_start] ||
|
33
|
+
params[:q][:bill_address_firstname_start] ||
|
34
|
+
params[:q][:bill_address_lastname_start]
|
35
|
+
@users = @users.with_email_or_address(params[:q][:email_start], address_params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_users_by_email
|
39
|
+
@users = @users.with_email(params[:q][:email_start])
|
40
|
+
end
|
41
|
+
|
42
|
+
def paginate_users
|
20
43
|
@users = @users.page(params[:page]).per(params[:per_page])
|
44
|
+
end
|
45
|
+
|
46
|
+
def prepare_index_response
|
47
|
+
paginate_users
|
21
48
|
expires_in 15.minutes, public: true
|
22
49
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
23
|
-
respond_with(@users)
|
24
50
|
end
|
25
51
|
|
26
52
|
def show
|
@@ -9,35 +9,12 @@ module Spree
|
|
9
9
|
rescue_from CanCan::AccessDenied, with: :access_denied
|
10
10
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
11
11
|
|
12
|
+
before_action :set_user_language
|
13
|
+
|
12
14
|
def content_type
|
13
15
|
Spree::Api::Config[:api_v2_content_type]
|
14
16
|
end
|
15
17
|
|
16
|
-
private
|
17
|
-
|
18
|
-
def serialize_collection(collection)
|
19
|
-
collection_serializer.new(
|
20
|
-
collection,
|
21
|
-
collection_options(collection)
|
22
|
-
).serializable_hash
|
23
|
-
end
|
24
|
-
|
25
|
-
def serialize_resource(resource)
|
26
|
-
resource_serializer.new(
|
27
|
-
resource,
|
28
|
-
include: resource_includes,
|
29
|
-
fields: sparse_fields
|
30
|
-
).serializable_hash
|
31
|
-
end
|
32
|
-
|
33
|
-
def paginated_collection
|
34
|
-
collection_paginator.new(sorted_collection, params).call
|
35
|
-
end
|
36
|
-
|
37
|
-
def collection_paginator
|
38
|
-
Spree::Api::Dependencies.storefront_collection_paginator.constantize
|
39
|
-
end
|
40
|
-
|
41
18
|
def render_serialized_payload(status = 200)
|
42
19
|
render json: yield, status: status, content_type: content_type
|
43
20
|
rescue ArgumentError => exception
|
@@ -118,6 +95,10 @@ module Spree
|
|
118
95
|
def gateway_error(exception)
|
119
96
|
render_error_payload(exception.message)
|
120
97
|
end
|
98
|
+
|
99
|
+
def set_user_language
|
100
|
+
I18n.locale = current_store.default_locale
|
101
|
+
end
|
121
102
|
end
|
122
103
|
end
|
123
104
|
end
|
@@ -0,0 +1,82 @@
|
|
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 serialize_collection(collection)
|
18
|
+
collection_serializer.new(
|
19
|
+
collection,
|
20
|
+
collection_options(collection)
|
21
|
+
).serializable_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize_resource(resource)
|
25
|
+
resource_serializer.new(
|
26
|
+
resource,
|
27
|
+
include: resource_includes,
|
28
|
+
fields: sparse_fields
|
29
|
+
).serializable_hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def paginated_collection
|
33
|
+
collection_paginator.new(sorted_collection, params).call
|
34
|
+
end
|
35
|
+
|
36
|
+
def collection_paginator
|
37
|
+
Spree::Api::Dependencies.storefront_collection_paginator.constantize
|
38
|
+
end
|
39
|
+
|
40
|
+
def sorted_collection
|
41
|
+
collection_sorter.new(collection, params, allowed_sort_attributes).call
|
42
|
+
end
|
43
|
+
|
44
|
+
def allowed_sort_attributes
|
45
|
+
default_sort_atributes
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_sort_atributes
|
49
|
+
[:id, :updated_at, :created_at]
|
50
|
+
end
|
51
|
+
|
52
|
+
def scope
|
53
|
+
model_class.accessible_by(current_ability, :show).includes(scope_includes)
|
54
|
+
end
|
55
|
+
|
56
|
+
def scope_includes
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
|
60
|
+
def resource
|
61
|
+
@resource ||= if defined?(resource_finder)
|
62
|
+
resource_finder.new(scope: scope, params: params).execute
|
63
|
+
else
|
64
|
+
scope.find(params[:id])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def collection
|
69
|
+
@collection ||= if defined?(collection_finder)
|
70
|
+
collection_finder.new(scope: scope, params: params).execute
|
71
|
+
else
|
72
|
+
scope
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def collection_sorter
|
77
|
+
Spree::Api::Dependencies.storefront_collection_sorter.constantize
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
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,6 +19,10 @@ 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
27
|
Spree::Api::Dependencies.storefront_order_serializer.constantize
|
39
28
|
end
|
@@ -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
|