spree_api 4.2.4 → 4.3.0.rc3
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/Rakefile +14 -1
- data/app/controllers/concerns/spree/api/v2/caching.rb +33 -0
- data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +23 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +4 -3
- data/app/controllers/spree/api/v1/orders_controller.rb +5 -1
- data/app/controllers/spree/api/v1/products_controller.rb +2 -2
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +31 -6
- data/app/controllers/spree/api/v2/platform/addresses_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/classifications_controller.rb +43 -0
- data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +34 -0
- data/app/controllers/spree/api/v2/platform/countries_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +35 -0
- data/app/controllers/spree/api/v2/platform/menus_controller.rb +23 -0
- data/app/controllers/spree/api/v2/platform/option_types_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/option_values_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/products_controller.rb +33 -0
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +115 -0
- data/app/controllers/spree/api/v2/platform/taxons_controller.rb +30 -0
- data/app/controllers/spree/api/v2/platform/users_controller.rb +28 -0
- data/app/controllers/spree/api/v2/resource_controller.rb +24 -7
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +2 -14
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +13 -11
- data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +6 -2
- data/app/controllers/spree/api/v2/storefront/account_controller.rb +32 -1
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +28 -6
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +2 -1
- data/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb +41 -0
- data/app/controllers/spree/api/v2/storefront/countries_controller.rb +16 -14
- data/app/controllers/spree/api/v2/storefront/menus_controller.rb +35 -0
- data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +10 -12
- data/app/controllers/spree/api/v2/storefront/stores_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +7 -8
- data/app/helpers/spree/api/v2/display_money_helper.rb +2 -2
- data/app/models/spree/api_configuration.rb +4 -1
- data/app/models/spree/api_dependencies.rb +20 -5
- data/app/serializers/concerns/spree/api/v2/image_transformation_concern.rb +15 -0
- data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +16 -0
- data/app/serializers/concerns/spree/api/v2/taxon_image_transformation_concern.rb +15 -0
- data/app/serializers/spree/api/v2/base_serializer.rb +32 -0
- data/app/serializers/spree/api/v2/platform/address_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/base_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/classification_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/country_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/icon_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/image_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +45 -0
- data/app/serializers/spree/api/v2/platform/menu_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/product_serializer.rb +78 -0
- data/app/serializers/spree/api/v2/platform/state_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +20 -0
- data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/store_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +38 -0
- data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +37 -0
- data/app/serializers/spree/api/v2/platform/variant_serializer.rb +57 -0
- data/app/serializers/spree/v2/storefront/base_serializer.rb +3 -2
- data/app/serializers/spree/v2/storefront/cms_page_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +28 -0
- data/app/serializers/spree/v2/storefront/country_serializer.rb +4 -4
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -0
- data/app/serializers/spree/v2/storefront/icon_serializer.rb +14 -0
- data/app/serializers/spree/v2/storefront/image_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/menu_item_serializer.rb +43 -0
- data/app/serializers/spree/v2/storefront/menu_serializer.rb +13 -0
- data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +4 -0
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_serializer.rb +21 -12
- data/app/serializers/spree/v2/storefront/store_serializer.rb +10 -0
- data/app/serializers/spree/v2/storefront/taxon_image_serializer.rb +3 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +6 -5
- data/config/initializers/doorkeeper.rb +8 -1
- data/config/initializers/rabl.rb +9 -0
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +115 -3
- data/db/migrate/20210727102516_change_integer_id_columns_type.rb +9 -0
- data/docs/oauth/index.yml +4 -4
- data/docs/v2/platform/index.yaml +3597 -0
- data/docs/v2/storefront/index.yaml +12117 -1610
- data/lib/spree/api/engine.rb +6 -17
- data/lib/spree/api/testing_support/v2/base.rb +1 -1
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +214 -0
- data/lib/spree/api/testing_support/v2/serializers_params.rb +14 -0
- data/lib/spree/api.rb +1 -0
- data/spree_api.gemspec +6 -3
- metadata +114 -13
- data/app/assets/javascripts/spree/api/main.js +0 -36
- data/app/assets/javascripts/spree/api/storefront/cart.js +0 -49
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bd9fd052b9bc9fd57cabf4fb28955081e4e3522aad98fe014641d46ca7b5c2c
|
|
4
|
+
data.tar.gz: f91442e429d34783f73dbc25806afa80ab0cbd5013c07c499c8b7da4bc5a29aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dcc5d4344630b798bb0ea424285c89267ec2034d2a2f2fb483686c17670793b13fb23499a10aec1c579a3c807cd995b2b6b9f6c33ba68cfe4da9883b57de017f
|
|
7
|
+
data.tar.gz: c9d7016ddc08b9d26a438b46a5374d1c229e90e51cb2bace94c4f616c647d13d37eecd913c10ed80126508e25b23d5054032f1bd4ef349098c2caa8fc8869ae6
|
data/Rakefile
CHANGED
|
@@ -3,7 +3,6 @@ require 'rake'
|
|
|
3
3
|
require 'rake/testtask'
|
|
4
4
|
require 'rspec/core/rake_task'
|
|
5
5
|
require 'spree/testing_support/common_rake'
|
|
6
|
-
require 'rails/all'
|
|
7
6
|
|
|
8
7
|
RSpec::Core::RakeTask.new
|
|
9
8
|
|
|
@@ -14,3 +13,17 @@ task :test_app do
|
|
|
14
13
|
ENV['LIB_NAME'] = 'spree/api'
|
|
15
14
|
Rake::Task['common:test_app'].invoke
|
|
16
15
|
end
|
|
16
|
+
|
|
17
|
+
namespace :rswag do
|
|
18
|
+
namespace :specs do
|
|
19
|
+
desc 'Generate Swagger JSON files from integration specs'
|
|
20
|
+
RSpec::Core::RakeTask.new('swaggerize') do |t|
|
|
21
|
+
t.pattern = ENV.fetch(
|
|
22
|
+
'PATTERN',
|
|
23
|
+
'spec/integration/**/*_spec.rb'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
t.rspec_opts = ['--format Rswag::Specs::SwaggerFormatter', '--order defined']
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Caching
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
def collection_cache_key(collection)
|
|
8
|
+
unscoped_collection = collection.unscope(:includes).unscope(:order)
|
|
9
|
+
cache_key_parts = [
|
|
10
|
+
self.class.to_s,
|
|
11
|
+
unscoped_collection.maximum(:updated_at),
|
|
12
|
+
unscoped_collection.ids,
|
|
13
|
+
resource_includes,
|
|
14
|
+
sparse_fields,
|
|
15
|
+
serializer_params,
|
|
16
|
+
params[:sort]&.strip,
|
|
17
|
+
params[:page]&.to_s&.strip,
|
|
18
|
+
params[:per_page]&.to_s&.strip,
|
|
19
|
+
].flatten.join('-')
|
|
20
|
+
|
|
21
|
+
Digest::MD5.hexdigest(cache_key_parts)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def collection_cache_opts
|
|
25
|
+
{
|
|
26
|
+
namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],
|
|
27
|
+
expires_in: Spree::Api::Config[:api_v2_collection_cache_ttl],
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module ProductListIncludes
|
|
5
|
+
def product_list_includes
|
|
6
|
+
variant_includes = {
|
|
7
|
+
prices: [],
|
|
8
|
+
option_values: :option_type,
|
|
9
|
+
images: []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
{
|
|
13
|
+
product_properties: [],
|
|
14
|
+
option_types: [],
|
|
15
|
+
variant_images: [],
|
|
16
|
+
master: variant_includes,
|
|
17
|
+
variants: variant_includes
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -9,9 +9,10 @@ module Spree
|
|
|
9
9
|
product_id: params[:product_id],
|
|
10
10
|
taxon_id: params[:taxon_id]
|
|
11
11
|
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
Spree::Dependencies.classification_reposition_service.constantize.call(
|
|
13
|
+
classification: classification,
|
|
14
|
+
position: params[:position]
|
|
15
|
+
)
|
|
15
16
|
head :ok
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -56,7 +56,7 @@ module Spree
|
|
|
56
56
|
|
|
57
57
|
def empty
|
|
58
58
|
authorize! :update, @order, order_token
|
|
59
|
-
@order
|
|
59
|
+
cart_empty_service.call(order: @order)
|
|
60
60
|
render plain: nil, status: 204
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -150,6 +150,10 @@ module Spree
|
|
|
150
150
|
def order_id
|
|
151
151
|
super || params[:id]
|
|
152
152
|
end
|
|
153
|
+
|
|
154
|
+
def cart_empty_service
|
|
155
|
+
Spree::Dependencies.cart_empty_service.constantize
|
|
156
|
+
end
|
|
153
157
|
end
|
|
154
158
|
end
|
|
155
159
|
end
|
|
@@ -64,7 +64,7 @@ module Spree
|
|
|
64
64
|
params[:product][:available_on] ||= Time.current
|
|
65
65
|
set_up_shipping_category
|
|
66
66
|
|
|
67
|
-
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
|
67
|
+
options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
|
|
68
68
|
@product = Core::Importer::Product.new(nil, product_params, options).create
|
|
69
69
|
|
|
70
70
|
if @product.persisted?
|
|
@@ -77,7 +77,7 @@ module Spree
|
|
|
77
77
|
def update
|
|
78
78
|
authorize! :update, @product
|
|
79
79
|
|
|
80
|
-
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
|
80
|
+
options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
|
|
81
81
|
@product = Core::Importer::Product.new(@product, product_params, options).update
|
|
82
82
|
|
|
83
83
|
if @product.errors.empty?
|
|
@@ -19,7 +19,7 @@ module Spree
|
|
|
19
19
|
|
|
20
20
|
def create
|
|
21
21
|
authorize! :create, Taxonomy
|
|
22
|
-
@taxonomy =
|
|
22
|
+
@taxonomy = current_store.taxonomies.new(taxonomy_params)
|
|
23
23
|
if @taxonomy.save
|
|
24
24
|
respond_with(@taxonomy, status: 201, default_template: :show)
|
|
25
25
|
else
|
|
@@ -7,8 +7,10 @@ module Spree
|
|
|
7
7
|
include Spree::Core::ControllerHelpers::Store
|
|
8
8
|
include Spree::Core::ControllerHelpers::Locale
|
|
9
9
|
include Spree::Core::ControllerHelpers::Currency
|
|
10
|
+
|
|
10
11
|
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
|
|
11
12
|
rescue_from CanCan::AccessDenied, with: :access_denied
|
|
13
|
+
rescue_from Doorkeeper::Errors::DoorkeeperError, with: :access_denied_401
|
|
12
14
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
|
13
15
|
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
|
14
16
|
if defined?(JSONAPI::Serializer::UnsupportedIncludeError)
|
|
@@ -39,7 +41,7 @@ module Spree
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def paginated_collection
|
|
42
|
-
collection_paginator.new(sorted_collection, params).call
|
|
44
|
+
@paginated_collection ||= collection_paginator.new(sorted_collection, params).call
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
def collection_paginator
|
|
@@ -51,10 +53,22 @@ module Spree
|
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def render_error_payload(error, status = 422)
|
|
54
|
-
if error.is_a?(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
json = if error.is_a?(ActiveModel::Errors)
|
|
57
|
+
{ error: error.full_messages.to_sentence, errors: error.messages }
|
|
58
|
+
elsif error.is_a?(Struct)
|
|
59
|
+
{ error: error.to_s, errors: error.to_h }
|
|
60
|
+
else
|
|
61
|
+
{ error: error }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
render json: json, status: status, content_type: content_type
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def render_result(result)
|
|
68
|
+
if result.success?
|
|
69
|
+
render_serialized_payload { serialize_resource(result.value) }
|
|
70
|
+
else
|
|
71
|
+
render_error_payload(result.error)
|
|
58
72
|
end
|
|
59
73
|
end
|
|
60
74
|
|
|
@@ -114,7 +128,14 @@ module Spree
|
|
|
114
128
|
end
|
|
115
129
|
|
|
116
130
|
def serializer_params
|
|
117
|
-
{
|
|
131
|
+
{
|
|
132
|
+
currency: current_currency,
|
|
133
|
+
locale: current_locale,
|
|
134
|
+
store: current_store,
|
|
135
|
+
user: spree_current_user,
|
|
136
|
+
image_transformation: params[:image_transformation],
|
|
137
|
+
taxon_image_transformation: params[:taxon_image_transformation]
|
|
138
|
+
}
|
|
118
139
|
end
|
|
119
140
|
|
|
120
141
|
def record_not_found
|
|
@@ -125,6 +146,10 @@ module Spree
|
|
|
125
146
|
render_error_payload(exception.message, 403)
|
|
126
147
|
end
|
|
127
148
|
|
|
149
|
+
def access_denied_401(exception)
|
|
150
|
+
render_error_payload(exception.message, 401)
|
|
151
|
+
end
|
|
152
|
+
|
|
128
153
|
def gateway_error(exception)
|
|
129
154
|
render_error_payload(exception.message)
|
|
130
155
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class AddressesController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Spree::Address
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:country, :state, :user]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class ClassificationsController < ResourceController
|
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
|
7
|
+
|
|
8
|
+
def reposition
|
|
9
|
+
spree_authorize! :update, resource if spree_current_user.present?
|
|
10
|
+
|
|
11
|
+
result = classification_reposition_service.call(
|
|
12
|
+
classification: resource,
|
|
13
|
+
position: permitted_resource_params[:position]
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if result.success?
|
|
17
|
+
render_serialized_payload { serialize_resource(result.value) }
|
|
18
|
+
else
|
|
19
|
+
render_error_payload(result.error)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def model_class
|
|
26
|
+
Spree::Classification
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def scope_includes
|
|
30
|
+
[
|
|
31
|
+
taxon: [],
|
|
32
|
+
product: [:variants_including_master, :variant_images, :master, variants: [:prices]]
|
|
33
|
+
]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def classification_reposition_service
|
|
37
|
+
Spree::Dependencies.classification_reposition_service.constantize
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class CmsSectionsController < ResourceController
|
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
|
7
|
+
|
|
8
|
+
def reposition
|
|
9
|
+
spree_authorize! :update, @moved_section if spree_current_user.present?
|
|
10
|
+
|
|
11
|
+
@moved_section = scope.find(params[:section_id])
|
|
12
|
+
new_index = params[:new_position_idx].to_i + 1
|
|
13
|
+
|
|
14
|
+
if @moved_section && new_index
|
|
15
|
+
@moved_section.set_list_position(new_index)
|
|
16
|
+
else
|
|
17
|
+
head :bad_request
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if @moved_section.save
|
|
21
|
+
head :no_content
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def model_class
|
|
28
|
+
Spree::CmsSection
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class CountriesController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Spree::Country
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:states, :zones]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class MenuItemsController < ResourceController
|
|
6
|
+
before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
|
|
7
|
+
|
|
8
|
+
def reposition
|
|
9
|
+
spree_authorize! :update, @moved_item if spree_current_user.present?
|
|
10
|
+
|
|
11
|
+
@moved_item = scope.find(params[:id])
|
|
12
|
+
@new_parent = scope.find(params[:new_parent_id])
|
|
13
|
+
new_index = params[:new_position_idx].to_i
|
|
14
|
+
|
|
15
|
+
if @moved_item && @new_parent && new_index
|
|
16
|
+
@moved_item.move_to_child_with_index(@new_parent, new_index)
|
|
17
|
+
else
|
|
18
|
+
head :bad_request
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if @moved_item.save
|
|
22
|
+
render_serialized_payload { serialize_resource(resource) }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def model_class
|
|
29
|
+
Spree::MenuItem
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
module Platform
|
|
5
|
+
class MenusController < ResourceController
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Spree::Menu
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scope_includes
|
|
13
|
+
[:menu_items]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def scope
|
|
17
|
+
current_store.menus
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|