spree_api 4.2.0.beta → 4.2.0.rc5
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 +0 -4
- 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 +12 -26
- data/app/controllers/spree/api/v2/resource_controller.rb +83 -0
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +69 -0
- 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/checkout_controller.rb +1 -2
- 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 +23 -0
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +4 -14
- 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_dependencies.rb +14 -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/cart_serializer.rb +3 -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/line_item_serializer.rb +2 -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 +6 -2
- data/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/stock_location_serializer.rb +11 -0
- 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 +15 -0
- 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/config/initializers/doorkeeper.rb +8 -1
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +2 -0
- data/docs/oauth/index.yml +78 -15
- data/docs/v2/storefront/index.yaml +3355 -661
- data/lib/spree/api/testing_support/v2/base.rb +1 -1
- data/lib/spree/api/testing_support/v2/current_order.rb +6 -0
- data/lib/spree_api.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +20 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4d89085eb3c34e7174431d231b1e9a883b6cbf3d7ee838d633125c352bd3a6db
|
|
4
|
+
data.tar.gz: 3402c8e857912d6655aea610e7092c4f749faf2f0b31a9f0c3f8601b292c43ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bef7abadbdf0a40b95b04b45811eade8884c5f782c9720a3b009e90aabc133b9384122e65fcc443245102b6e444636e30f423d357efefebc8e63910240525efe
|
|
7
|
+
data.tar.gz: a1824c2bccb63b030b8d6cfe64237b1ce3b57dfd36adacdf71367b5a0408cec84a7d019bec4017c4d83f273a2de0e595d734cf506cb517b03b78932f9a871285
|
|
@@ -34,10 +34,6 @@ module Spree
|
|
|
34
34
|
)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def supported_currencies
|
|
38
|
-
current_store.supported_currencies_list
|
|
39
|
-
end
|
|
40
|
-
|
|
41
37
|
def serialize_order(order)
|
|
42
38
|
resource_serializer.new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
|
|
43
39
|
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,6 +5,8 @@ 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,31 +15,6 @@ module Spree
|
|
|
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
|
|
@@ -53,7 +30,12 @@ module Spree
|
|
|
53
30
|
end
|
|
54
31
|
|
|
55
32
|
def spree_current_user
|
|
56
|
-
|
|
33
|
+
return nil unless doorkeeper_token
|
|
34
|
+
return @spree_current_user if @spree_current_user
|
|
35
|
+
|
|
36
|
+
doorkeeper_authorize!
|
|
37
|
+
|
|
38
|
+
@spree_current_user ||= Spree.user_class.find_by(id: doorkeeper_token.resource_owner_id)
|
|
57
39
|
end
|
|
58
40
|
|
|
59
41
|
def spree_authorize!(action, subject, *args)
|
|
@@ -102,6 +84,10 @@ module Spree
|
|
|
102
84
|
fields.presence
|
|
103
85
|
end
|
|
104
86
|
|
|
87
|
+
def serializer_params
|
|
88
|
+
{ currency: current_currency, store: current_store, user: spree_current_user }
|
|
89
|
+
end
|
|
90
|
+
|
|
105
91
|
def record_not_found
|
|
106
92
|
render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
|
|
107
93
|
end
|
|
@@ -0,0 +1,83 @@
|
|
|
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).merge(params: serializer_params)
|
|
21
|
+
).serializable_hash
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def serialize_resource(resource)
|
|
25
|
+
resource_serializer.new(
|
|
26
|
+
resource,
|
|
27
|
+
params: serializer_params,
|
|
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
|
+
def sorted_collection
|
|
42
|
+
collection_sorter.new(collection, params, allowed_sort_attributes).call
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def allowed_sort_attributes
|
|
46
|
+
default_sort_atributes
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def default_sort_atributes
|
|
50
|
+
[:id, :updated_at, :created_at]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def scope
|
|
54
|
+
model_class.accessible_by(current_ability, :show).includes(scope_includes)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def scope_includes
|
|
58
|
+
[]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def resource
|
|
62
|
+
@resource ||= if defined?(resource_finder)
|
|
63
|
+
resource_finder.new(scope: scope, params: params).execute
|
|
64
|
+
else
|
|
65
|
+
scope.find(params[:id])
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def collection
|
|
70
|
+
@collection ||= if defined?(collection_finder)
|
|
71
|
+
collection_finder.new(scope: scope, params: params).execute
|
|
72
|
+
else
|
|
73
|
+
scope
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def collection_sorter
|
|
78
|
+
Spree::Api::Dependencies.storefront_collection_sorter.constantize
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Storefront
|
|
5
|
+
module Account
|
|
6
|
+
class AddressesController < ::Spree::Api::V2::ResourceController
|
|
7
|
+
before_action :require_spree_current_user
|
|
8
|
+
|
|
9
|
+
def create
|
|
10
|
+
result = create_service.call(user: spree_current_user, address_params: address_params)
|
|
11
|
+
render_result(result)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def update
|
|
15
|
+
result = update_service.call(address: resource, address_params: address_params)
|
|
16
|
+
render_result(result)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def collection
|
|
22
|
+
collection_finder.new(scope: scope, params: params).execute
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def model_class
|
|
26
|
+
Spree::Address
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def collection_finder
|
|
30
|
+
Spree::Api::Dependencies.storefront_address_finder.constantize
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def collection_serializer
|
|
34
|
+
Spree::Api::Dependencies.storefront_address_serializer.constantize
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def resource_serializer
|
|
38
|
+
Spree::Api::Dependencies.storefront_address_serializer.constantize
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def serialize_collection(collection)
|
|
42
|
+
collection_serializer.new(collection).serializable_hash
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def create_service
|
|
46
|
+
Spree::Api::Dependencies.storefront_account_create_address_service.constantize
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def update_service
|
|
50
|
+
Spree::Api::Dependencies.storefront_account_update_address_service.constantize
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def address_params
|
|
54
|
+
params.require(:address).permit(permitted_address_attributes)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def render_result(result)
|
|
58
|
+
if result.success?
|
|
59
|
+
render_serialized_payload { serialize_resource(result.value) }
|
|
60
|
+
else
|
|
61
|
+
render_error_payload(result.error)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -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
|