spree_api 4.4.0.rc2 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +10 -8
- data/app/controllers/spree/api/v2/platform/orders_controller.rb +1 -1
- data/app/controllers/spree/api/v2/platform/products_controller.rb +5 -1
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +5 -1
- data/app/controllers/spree/api/v2/storefront/stores_controller.rb +4 -0
- data/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb +35 -0
- data/app/models/concerns/spree/webhooks/has_webhooks.rb +34 -8
- data/app/models/spree/api/webhooks/product_decorator.rb +21 -2
- data/app/models/spree/webhooks/subscriber.rb +4 -0
- data/app/serializers/spree/api/v2/platform/cms_section_image_one_serializer.rb +9 -0
- data/app/serializers/spree/api/v2/platform/cms_section_image_three_serializer.rb +9 -0
- data/app/serializers/spree/api/v2/platform/cms_section_image_two_serializer.rb +9 -0
- data/app/serializers/spree/api/v2/platform/hero_image_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/image_gallery_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/side_by_side_image_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -0
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +3 -3
- data/app/serializers/spree/v2/storefront/order_serializer.rb +9 -0
- data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -0
- data/app/serializers/spree/v2/storefront/store_serializer.rb +5 -10
- data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
- data/app/services/spree/webhooks/subscribers/queue_requests.rb +8 -2
- data/config/routes.rb +1 -120
- data/docs/v2/platform/index.yaml +1597 -998
- data/docs/v2/storefront/index.yaml +357 -33
- data/lib/spree/api/configuration.rb +11 -0
- data/lib/spree/api/dependencies.rb +165 -0
- data/lib/spree/api/engine.rb +5 -23
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +0 -1
- data/lib/spree/api.rb +0 -4
- data/lib/spree_api.rb +0 -1
- data/spree_api.gemspec +0 -2
- metadata +18 -179
- data/app/controllers/spree/api/base_controller.rb +0 -171
- data/app/controllers/spree/api/v1/addresses_controller.rb +0 -46
- data/app/controllers/spree/api/v1/checkouts_controller.rb +0 -106
- data/app/controllers/spree/api/v1/classifications_controller.rb +0 -21
- data/app/controllers/spree/api/v1/countries_controller.rb +0 -22
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +0 -26
- data/app/controllers/spree/api/v1/customer_returns_controller.rb +0 -25
- data/app/controllers/spree/api/v1/images_controller.rb +0 -58
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +0 -54
- data/app/controllers/spree/api/v1/line_items_controller.rb +0 -70
- data/app/controllers/spree/api/v1/option_types_controller.rb +0 -60
- data/app/controllers/spree/api/v1/option_values_controller.rb +0 -62
- data/app/controllers/spree/api/v1/orders_controller.rb +0 -160
- data/app/controllers/spree/api/v1/payments_controller.rb +0 -82
- data/app/controllers/spree/api/v1/product_properties_controller.rb +0 -73
- data/app/controllers/spree/api/v1/products_controller.rb +0 -131
- data/app/controllers/spree/api/v1/promotions_controller.rb +0 -30
- data/app/controllers/spree/api/v1/properties_controller.rb +0 -70
- data/app/controllers/spree/api/v1/reimbursements_controller.rb +0 -25
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -70
- data/app/controllers/spree/api/v1/shipments_controller.rb +0 -196
- data/app/controllers/spree/api/v1/states_controller.rb +0 -36
- data/app/controllers/spree/api/v1/stock_items_controller.rb +0 -82
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +0 -53
- data/app/controllers/spree/api/v1/stock_movements_controller.rb +0 -45
- data/app/controllers/spree/api/v1/stores_controller.rb +0 -56
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +0 -67
- data/app/controllers/spree/api/v1/taxons_controller.rb +0 -100
- data/app/controllers/spree/api/v1/users_controller.rb +0 -97
- data/app/controllers/spree/api/v1/variants_controller.rb +0 -81
- data/app/controllers/spree/api/v1/zones_controller.rb +0 -55
- data/app/helpers/spree/api/api_helpers.rb +0 -190
- data/app/models/spree/api_configuration.rb +0 -10
- data/app/views/spree/api/errors/gateway_error.rabl +0 -2
- data/app/views/spree/api/errors/invalid_api_key.rabl +0 -2
- data/app/views/spree/api/errors/invalid_resource.rabl +0 -3
- data/app/views/spree/api/errors/must_specify_api_key.rabl +0 -2
- data/app/views/spree/api/errors/not_found.rabl +0 -2
- data/app/views/spree/api/errors/unauthorized.rabl +0 -2
- data/app/views/spree/api/v1/addresses/show.rabl +0 -10
- data/app/views/spree/api/v1/adjustments/show.rabl +0 -4
- data/app/views/spree/api/v1/countries/index.rabl +0 -7
- data/app/views/spree/api/v1/countries/show.rabl +0 -5
- data/app/views/spree/api/v1/credit_cards/index.rabl +0 -7
- data/app/views/spree/api/v1/credit_cards/show.rabl +0 -3
- data/app/views/spree/api/v1/customer_returns/index.rabl +0 -7
- data/app/views/spree/api/v1/images/index.rabl +0 -4
- data/app/views/spree/api/v1/images/new.rabl +0 -3
- data/app/views/spree/api/v1/images/show.rabl +0 -6
- data/app/views/spree/api/v1/inventory_units/show.rabl +0 -2
- data/app/views/spree/api/v1/line_items/new.rabl +0 -3
- data/app/views/spree/api/v1/line_items/show.rabl +0 -14
- data/app/views/spree/api/v1/option_types/index.rabl +0 -3
- data/app/views/spree/api/v1/option_types/new.rabl +0 -3
- data/app/views/spree/api/v1/option_types/show.rabl +0 -5
- data/app/views/spree/api/v1/option_values/index.rabl +0 -3
- data/app/views/spree/api/v1/option_values/new.rabl +0 -3
- data/app/views/spree/api/v1/option_values/show.rabl +0 -2
- data/app/views/spree/api/v1/orders/address.rabl +0 -0
- data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
- data/app/views/spree/api/v1/orders/cart.rabl +0 -0
- data/app/views/spree/api/v1/orders/complete.rabl +0 -0
- data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +0 -2
- data/app/views/spree/api/v1/orders/could_not_transition.rabl +0 -3
- data/app/views/spree/api/v1/orders/index.rabl +0 -7
- data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +0 -2
- data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +0 -2
- data/app/views/spree/api/v1/orders/mine.rabl +0 -9
- data/app/views/spree/api/v1/orders/order.rabl +0 -10
- data/app/views/spree/api/v1/orders/payment.rabl +0 -3
- data/app/views/spree/api/v1/orders/show.rabl +0 -51
- data/app/views/spree/api/v1/payments/credit_over_limit.rabl +0 -2
- data/app/views/spree/api/v1/payments/index.rabl +0 -7
- data/app/views/spree/api/v1/payments/new.rabl +0 -5
- data/app/views/spree/api/v1/payments/show.rabl +0 -2
- data/app/views/spree/api/v1/payments/update_forbidden.rabl +0 -2
- data/app/views/spree/api/v1/product_properties/index.rabl +0 -7
- data/app/views/spree/api/v1/product_properties/new.rabl +0 -2
- data/app/views/spree/api/v1/product_properties/show.rabl +0 -2
- data/app/views/spree/api/v1/products/index.rabl +0 -9
- data/app/views/spree/api/v1/products/new.rabl +0 -3
- data/app/views/spree/api/v1/products/product.rabl +0 -1
- data/app/views/spree/api/v1/products/show.rabl +0 -36
- data/app/views/spree/api/v1/promotions/handler.rabl +0 -5
- data/app/views/spree/api/v1/promotions/show.rabl +0 -2
- data/app/views/spree/api/v1/properties/index.rabl +0 -7
- data/app/views/spree/api/v1/properties/new.rabl +0 -2
- data/app/views/spree/api/v1/properties/show.rabl +0 -2
- data/app/views/spree/api/v1/reimbursements/index.rabl +0 -7
- data/app/views/spree/api/v1/return_authorizations/index.rabl +0 -7
- data/app/views/spree/api/v1/return_authorizations/new.rabl +0 -3
- data/app/views/spree/api/v1/return_authorizations/show.rabl +0 -2
- data/app/views/spree/api/v1/shared/stock_location_required.rabl +0 -2
- data/app/views/spree/api/v1/shipments/big.rabl +0 -48
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +0 -2
- data/app/views/spree/api/v1/shipments/mine.rabl +0 -9
- data/app/views/spree/api/v1/shipments/show.rabl +0 -32
- data/app/views/spree/api/v1/shipments/small.rabl +0 -37
- data/app/views/spree/api/v1/shipping_rates/show.rabl +0 -2
- data/app/views/spree/api/v1/states/index.rabl +0 -12
- data/app/views/spree/api/v1/states/show.rabl +0 -2
- data/app/views/spree/api/v1/stock_items/index.rabl +0 -7
- data/app/views/spree/api/v1/stock_items/show.rabl +0 -5
- data/app/views/spree/api/v1/stock_locations/index.rabl +0 -7
- data/app/views/spree/api/v1/stock_locations/show.rabl +0 -8
- data/app/views/spree/api/v1/stock_movements/index.rabl +0 -7
- data/app/views/spree/api/v1/stock_movements/show.rabl +0 -5
- data/app/views/spree/api/v1/stores/index.rabl +0 -4
- data/app/views/spree/api/v1/stores/show.rabl +0 -2
- data/app/views/spree/api/v1/tags/index.rabl +0 -9
- data/app/views/spree/api/v1/taxonomies/index.rabl +0 -7
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +0 -7
- data/app/views/spree/api/v1/taxonomies/nested.rabl +0 -11
- data/app/views/spree/api/v1/taxonomies/new.rabl +0 -3
- data/app/views/spree/api/v1/taxonomies/show.rabl +0 -15
- data/app/views/spree/api/v1/taxons/index.rabl +0 -10
- data/app/views/spree/api/v1/taxons/jstree.rabl +0 -7
- data/app/views/spree/api/v1/taxons/new.rabl +0 -3
- data/app/views/spree/api/v1/taxons/show.rabl +0 -6
- data/app/views/spree/api/v1/taxons/taxons.rabl +0 -5
- data/app/views/spree/api/v1/users/index.rabl +0 -7
- data/app/views/spree/api/v1/users/new.rabl +0 -3
- data/app/views/spree/api/v1/users/show.rabl +0 -11
- data/app/views/spree/api/v1/variants/big.rabl +0 -14
- data/app/views/spree/api/v1/variants/index.rabl +0 -9
- data/app/views/spree/api/v1/variants/new.rabl +0 -2
- data/app/views/spree/api/v1/variants/show.rabl +0 -3
- data/app/views/spree/api/v1/variants/small.rabl +0 -18
- data/app/views/spree/api/v1/zones/index.rabl +0 -7
- data/app/views/spree/api/v1/zones/show.rabl +0 -6
- data/config/initializers/rabl.rb +0 -9
- data/lib/spree/api/api_dependencies.rb +0 -163
- data/lib/spree/api/controller_setup.rb +0 -19
- data/lib/spree/api/responders/rabl_template.rb +0 -28
- data/lib/spree/api/responders.rb +0 -11
- data/lib/spree/api/testing_support/helpers.rb +0 -44
- data/lib/spree/api/testing_support/setup.rb +0 -16
@@ -1,100 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V1
|
4
|
-
class TaxonsController < Spree::Api::BaseController
|
5
|
-
def index
|
6
|
-
@taxons = if taxonomy
|
7
|
-
taxonomy.root.children
|
8
|
-
elsif params[:ids]
|
9
|
-
Spree::Taxon.includes(:children).accessible_by(current_ability).where(id: params[:ids].split(','))
|
10
|
-
else
|
11
|
-
Spree::Taxon.includes(:children).accessible_by(current_ability).order(:taxonomy_id, :lft)
|
12
|
-
end
|
13
|
-
@taxons = @taxons.ransack(params[:q]).result
|
14
|
-
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
15
|
-
respond_with(@taxons)
|
16
|
-
end
|
17
|
-
|
18
|
-
def show
|
19
|
-
@taxon = taxon
|
20
|
-
respond_with(@taxon)
|
21
|
-
end
|
22
|
-
|
23
|
-
def jstree
|
24
|
-
show
|
25
|
-
end
|
26
|
-
|
27
|
-
def new; end
|
28
|
-
|
29
|
-
def create
|
30
|
-
authorize! :create, Taxon
|
31
|
-
@taxon = Spree::Taxon.new(taxon_params)
|
32
|
-
@taxon.taxonomy_id = params[:taxonomy_id]
|
33
|
-
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
34
|
-
|
35
|
-
if taxonomy.nil?
|
36
|
-
@taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
|
37
|
-
invalid_resource!(@taxon) and return
|
38
|
-
end
|
39
|
-
|
40
|
-
@taxon.parent_id = taxonomy.root_id unless params[:taxon][:parent_id]
|
41
|
-
|
42
|
-
if @taxon.save
|
43
|
-
respond_with(@taxon, status: 201, default_template: :show)
|
44
|
-
else
|
45
|
-
invalid_resource!(@taxon)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def update
|
50
|
-
authorize! :update, taxon
|
51
|
-
if taxon.update(taxon_params)
|
52
|
-
respond_with(taxon, status: 200, default_template: :show)
|
53
|
-
else
|
54
|
-
invalid_resource!(taxon)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def destroy
|
59
|
-
authorize! :destroy, taxon
|
60
|
-
taxon.destroy
|
61
|
-
respond_with(taxon, status: 204)
|
62
|
-
end
|
63
|
-
|
64
|
-
def products
|
65
|
-
# Returns the products sorted by their position with the classification
|
66
|
-
# Products#index does not do the sorting.
|
67
|
-
taxon = Spree::Taxon.find(params[:id])
|
68
|
-
@products = taxon.products.ransack(params[:q]).result
|
69
|
-
@products = @products.page(params[:page]).per(params[:per_page] || 500)
|
70
|
-
render 'spree/api/v1/products/index'
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def taxonomy
|
76
|
-
if params[:taxonomy_id].present?
|
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
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def taxon
|
87
|
-
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :show).find(params[:id])
|
88
|
-
end
|
89
|
-
|
90
|
-
def taxon_params
|
91
|
-
if params[:taxon] && !params[:taxon].empty?
|
92
|
-
params.require(:taxon).permit(permitted_taxon_attributes)
|
93
|
-
else
|
94
|
-
{}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V1
|
4
|
-
class UsersController < Spree::Api::BaseController
|
5
|
-
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
6
|
-
|
7
|
-
def index
|
8
|
-
users
|
9
|
-
|
10
|
-
if params[: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
|
16
|
-
end
|
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
|
43
|
-
@users = @users.page(params[:page]).per(params[:per_page])
|
44
|
-
end
|
45
|
-
|
46
|
-
def prepare_index_response
|
47
|
-
paginate_users
|
48
|
-
expires_in 15.minutes, public: true
|
49
|
-
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def show
|
53
|
-
respond_with(user)
|
54
|
-
end
|
55
|
-
|
56
|
-
def new; end
|
57
|
-
|
58
|
-
def create
|
59
|
-
authorize! :create, Spree.user_class
|
60
|
-
@user = Spree.user_class.new(user_params)
|
61
|
-
if @user.save
|
62
|
-
respond_with(@user, status: 201, default_template: :show)
|
63
|
-
else
|
64
|
-
invalid_resource!(@user)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def update
|
69
|
-
authorize! :update, user
|
70
|
-
if user.update(user_params)
|
71
|
-
respond_with(user, status: 200, default_template: :show)
|
72
|
-
else
|
73
|
-
invalid_resource!(user)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def destroy
|
78
|
-
authorize! :destroy, user
|
79
|
-
user.destroy
|
80
|
-
respond_with(user, status: 204)
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def user
|
86
|
-
@user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:id])
|
87
|
-
end
|
88
|
-
|
89
|
-
def user_params
|
90
|
-
params.require(:user).permit(permitted_user_attributes |
|
91
|
-
[bill_address_attributes: permitted_address_attributes,
|
92
|
-
ship_address_attributes: permitted_address_attributes])
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V1
|
4
|
-
class VariantsController < Spree::Api::BaseController
|
5
|
-
before_action :product
|
6
|
-
|
7
|
-
def create
|
8
|
-
authorize! :create, Variant
|
9
|
-
@variant = scope.new(variant_params)
|
10
|
-
if @variant.save
|
11
|
-
respond_with(@variant, status: 201, default_template: :show)
|
12
|
-
else
|
13
|
-
invalid_resource!(@variant)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def destroy
|
18
|
-
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
19
|
-
@variant.destroy
|
20
|
-
respond_with(@variant, status: 204)
|
21
|
-
end
|
22
|
-
|
23
|
-
# The lazyloaded associations here are pretty much attached to which nodes
|
24
|
-
# we render on the view so we better update it any time a node is included
|
25
|
-
# or removed from the views.
|
26
|
-
def index
|
27
|
-
@variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.
|
28
|
-
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
29
|
-
respond_with(@variants)
|
30
|
-
end
|
31
|
-
|
32
|
-
def new; end
|
33
|
-
|
34
|
-
def show
|
35
|
-
@variant = scope.includes(*variant_includes).find(params[:id])
|
36
|
-
respond_with(@variant)
|
37
|
-
end
|
38
|
-
|
39
|
-
def update
|
40
|
-
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
41
|
-
if @variant.update(variant_params)
|
42
|
-
respond_with(@variant, status: 200, default_template: :show)
|
43
|
-
else
|
44
|
-
invalid_resource!(@product)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def product
|
51
|
-
if params[:product_id]
|
52
|
-
@product ||= Spree::Product.accessible_by(current_ability, :show).
|
53
|
-
friendly.find(params[:product_id])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def scope
|
58
|
-
variants = if @product
|
59
|
-
@product.variants_including_master
|
60
|
-
else
|
61
|
-
Variant
|
62
|
-
end
|
63
|
-
|
64
|
-
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
65
|
-
variants = variants.with_deleted
|
66
|
-
end
|
67
|
-
|
68
|
-
variants.eligible.accessible_by(current_ability)
|
69
|
-
end
|
70
|
-
|
71
|
-
def variant_params
|
72
|
-
params.require(:variant).permit(permitted_variant_attributes)
|
73
|
-
end
|
74
|
-
|
75
|
-
def variant_includes
|
76
|
-
[{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module V1
|
4
|
-
class ZonesController < Spree::Api::BaseController
|
5
|
-
def create
|
6
|
-
authorize! :create, Zone
|
7
|
-
@zone = Spree::Zone.new(zone_params)
|
8
|
-
if @zone.save
|
9
|
-
respond_with(@zone, status: 201, default_template: :show)
|
10
|
-
else
|
11
|
-
invalid_resource!(@zone)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
authorize! :destroy, zone
|
17
|
-
zone.destroy
|
18
|
-
respond_with(zone, status: 204)
|
19
|
-
end
|
20
|
-
|
21
|
-
def index
|
22
|
-
@zones = Zone.accessible_by(current_ability).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
23
|
-
respond_with(@zones)
|
24
|
-
end
|
25
|
-
|
26
|
-
def show
|
27
|
-
respond_with(zone)
|
28
|
-
end
|
29
|
-
|
30
|
-
def update
|
31
|
-
authorize! :update, zone
|
32
|
-
if zone.update(zone_params)
|
33
|
-
respond_with(zone, status: 200, default_template: :show)
|
34
|
-
else
|
35
|
-
invalid_resource!(zone)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def zone_params
|
42
|
-
attrs = params.require(:zone).permit!
|
43
|
-
if attrs[:zone_members]
|
44
|
-
attrs[:zone_members_attributes] = attrs.delete(:zone_members)
|
45
|
-
end
|
46
|
-
attrs
|
47
|
-
end
|
48
|
-
|
49
|
-
def zone
|
50
|
-
@zone ||= Spree::Zone.accessible_by(current_ability, :show).find(params[:id])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
module ApiHelpers
|
4
|
-
ATTRIBUTES = [
|
5
|
-
:product_attributes,
|
6
|
-
:product_property_attributes,
|
7
|
-
:variant_attributes,
|
8
|
-
:image_attributes,
|
9
|
-
:option_value_attributes,
|
10
|
-
:order_attributes,
|
11
|
-
:line_item_attributes,
|
12
|
-
:option_type_attributes,
|
13
|
-
:payment_attributes,
|
14
|
-
:payment_method_attributes,
|
15
|
-
:shipment_attributes,
|
16
|
-
:taxonomy_attributes,
|
17
|
-
:taxon_attributes,
|
18
|
-
:address_attributes,
|
19
|
-
:country_attributes,
|
20
|
-
:state_attributes,
|
21
|
-
:adjustment_attributes,
|
22
|
-
:inventory_unit_attributes,
|
23
|
-
:return_authorization_attributes,
|
24
|
-
:creditcard_attributes,
|
25
|
-
:payment_source_attributes,
|
26
|
-
:user_attributes,
|
27
|
-
:property_attributes,
|
28
|
-
:stock_location_attributes,
|
29
|
-
:stock_movement_attributes,
|
30
|
-
:stock_item_attributes,
|
31
|
-
:promotion_attributes,
|
32
|
-
:store_attributes,
|
33
|
-
:tag_attributes,
|
34
|
-
:customer_return_attributes,
|
35
|
-
:reimbursement_attributes
|
36
|
-
]
|
37
|
-
|
38
|
-
mattr_reader *ATTRIBUTES
|
39
|
-
|
40
|
-
def required_fields_for(model)
|
41
|
-
required_fields = model._validators.select do |_field, validations|
|
42
|
-
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
43
|
-
end.map(&:first) # get fields that are invalid
|
44
|
-
# Permalinks presence is validated, but are really automatically generated
|
45
|
-
# Therefore we shouldn't tell API clients that they MUST send one through
|
46
|
-
required_fields.map!(&:to_s).delete('permalink')
|
47
|
-
# Do not require slugs, either
|
48
|
-
required_fields.delete('slug')
|
49
|
-
required_fields
|
50
|
-
end
|
51
|
-
|
52
|
-
@@product_attributes = [
|
53
|
-
:id, :name, :description, :price, :display_price, :available_on,
|
54
|
-
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
55
|
-
:taxon_ids, :total_on_hand
|
56
|
-
]
|
57
|
-
|
58
|
-
@@product_property_attributes = [
|
59
|
-
:id, :product_id, :property_id, :value, :property_name
|
60
|
-
]
|
61
|
-
|
62
|
-
@@variant_attributes = [
|
63
|
-
:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
|
64
|
-
:slug, :description, :track_inventory
|
65
|
-
]
|
66
|
-
|
67
|
-
@@image_attributes = [
|
68
|
-
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
69
|
-
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
70
|
-
]
|
71
|
-
|
72
|
-
@@option_value_attributes = [
|
73
|
-
:id, :name, :presentation, :option_type_name, :option_type_id,
|
74
|
-
:option_type_presentation
|
75
|
-
]
|
76
|
-
|
77
|
-
@@order_attributes = [
|
78
|
-
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
79
|
-
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
80
|
-
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
81
|
-
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
82
|
-
:display_additional_tax_total, :tax_total, :currency, :considered_risky,
|
83
|
-
:canceler_id
|
84
|
-
]
|
85
|
-
|
86
|
-
@@line_item_attributes = [:id, :quantity, :price, :variant_id]
|
87
|
-
|
88
|
-
@@option_type_attributes = [:id, :name, :presentation, :position]
|
89
|
-
|
90
|
-
@@payment_attributes = [
|
91
|
-
:id, :source_type, :source_id, :amount, :display_amount,
|
92
|
-
:payment_method_id, :state, :avs_response, :created_at,
|
93
|
-
:updated_at, :number
|
94
|
-
]
|
95
|
-
|
96
|
-
@@payment_method_attributes = [:id, :name, :description]
|
97
|
-
|
98
|
-
@@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
|
99
|
-
|
100
|
-
@@taxonomy_attributes = [:id, :name]
|
101
|
-
|
102
|
-
@@taxon_attributes = [
|
103
|
-
:id, :name, :pretty_name, :permalink, :parent_id,
|
104
|
-
:taxonomy_id, :meta_title, :meta_description
|
105
|
-
]
|
106
|
-
|
107
|
-
@@inventory_unit_attributes = [
|
108
|
-
:id, :lock_version, :state, :variant_id, :shipment_id,
|
109
|
-
:return_authorization_id
|
110
|
-
]
|
111
|
-
|
112
|
-
@@return_authorization_attributes = [
|
113
|
-
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
114
|
-
]
|
115
|
-
|
116
|
-
@@address_attributes = [
|
117
|
-
:id, :firstname, :lastname, :full_name, :address1, :address2, :city,
|
118
|
-
:zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
|
119
|
-
:label, :state_name, :state_text
|
120
|
-
]
|
121
|
-
|
122
|
-
@@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
123
|
-
|
124
|
-
@@state_attributes = [:id, :name, :abbr, :country_id]
|
125
|
-
|
126
|
-
@@adjustment_attributes = [
|
127
|
-
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
128
|
-
:originator_type, :originator_id, :amount, :label, :mandatory,
|
129
|
-
:locked, :eligible, :created_at, :updated_at
|
130
|
-
]
|
131
|
-
|
132
|
-
@@creditcard_attributes = [
|
133
|
-
:id, :month, :year, :cc_type, :last_digits, :name,
|
134
|
-
:gateway_customer_profile_id, :gateway_payment_profile_id
|
135
|
-
]
|
136
|
-
|
137
|
-
@@payment_source_attributes = [
|
138
|
-
:id, :month, :year, :cc_type, :last_digits, :name
|
139
|
-
]
|
140
|
-
|
141
|
-
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
142
|
-
|
143
|
-
@@property_attributes = [:id, :name, :presentation]
|
144
|
-
|
145
|
-
@@stock_location_attributes = [
|
146
|
-
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
147
|
-
:country_id, :zipcode, :phone, :active
|
148
|
-
]
|
149
|
-
|
150
|
-
@@stock_movement_attributes = [:id, :quantity, :stock_item_id]
|
151
|
-
|
152
|
-
@@stock_item_attributes = [
|
153
|
-
:id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
|
154
|
-
:variant_id
|
155
|
-
]
|
156
|
-
|
157
|
-
@@promotion_attributes = [
|
158
|
-
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
159
|
-
:match_policy, :code, :advertise, :path
|
160
|
-
]
|
161
|
-
|
162
|
-
@@store_attributes = [
|
163
|
-
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
164
|
-
:mail_from_address, :customer_support_email, :default_currency,
|
165
|
-
:code, :default, :facebook, :twitter, :instagram,
|
166
|
-
:supported_currencies, :default_locale, :supported_locales
|
167
|
-
]
|
168
|
-
|
169
|
-
@@tag_attributes = [:id, :name]
|
170
|
-
|
171
|
-
@@customer_return_attributes = [
|
172
|
-
:id, :number, :order_id, :fully_reimbursed?, :pre_tax_total,
|
173
|
-
:created_at, :updated_at
|
174
|
-
]
|
175
|
-
|
176
|
-
@@reimbursement_attributes = [
|
177
|
-
:id, :reimbursement_status, :customer_return_id, :order_id,
|
178
|
-
:number, :total, :created_at, :updated_at
|
179
|
-
]
|
180
|
-
|
181
|
-
def variant_attributes
|
182
|
-
if @current_user_roles&.include?('admin')
|
183
|
-
@@variant_attributes + [:cost_price]
|
184
|
-
else
|
185
|
-
@@variant_attributes
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
class ApiConfiguration < Preferences::Configuration
|
3
|
-
preference :requires_authentication, :boolean, default: true
|
4
|
-
preference :api_v2_serializers_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
5
|
-
preference :api_v2_collection_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
6
|
-
preference :api_v2_collection_cache_namespace, :string, default: 'api_v2_collection_cache'
|
7
|
-
preference :api_v2_content_type, :string, default: 'application/vnd.api+json'
|
8
|
-
preference :api_v2_per_page_limit, :integer, default: 500
|
9
|
-
end
|
10
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
object @line_item
|
2
|
-
cache [I18n.locale, root_object]
|
3
|
-
attributes *line_item_attributes
|
4
|
-
node(:single_display_amount) { |li| li.single_display_amount.to_s }
|
5
|
-
node(:display_amount) { |li| li.display_amount.to_s }
|
6
|
-
node(:total, &:total)
|
7
|
-
child :variant do
|
8
|
-
extends 'spree/api/v1/variants/small'
|
9
|
-
attributes :product_id
|
10
|
-
end
|
11
|
-
|
12
|
-
child adjustments: :adjustments do
|
13
|
-
extends 'spree/api/v1/adjustments/show'
|
14
|
-
end
|