spree_api 3.0.10 → 3.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +21 -22
- data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
- data/app/controllers/spree/api/v1/images_controller.rb +56 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
- data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
- data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
- data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
- data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/spree/api/v1/products_controller.rb +126 -0
- data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
- data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
- data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
- data/app/controllers/spree/api/v1/states_controller.rb +37 -0
- data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
- data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
- data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
- data/app/controllers/spree/api/v1/users_controller.rb +60 -0
- data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
- data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -2
- data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
- data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
- data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
- data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
- data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
- data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
- data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
- data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
- data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
- data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
- data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
- data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
- data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
- data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
- data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
- data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
- data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
- data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
- data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
- data/config/routes.rb +85 -88
- data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
- data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
- data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
- data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
- data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
- data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
- data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
- data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
- data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
- data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
- data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
- data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/requests/ransackable_attributes_spec.rb +6 -6
- data/spec/requests/version_spec.rb +19 -0
- data/spree_api.gemspec +1 -1
- metadata +188 -185
- data/CHANGELOG.md +0 -3
- data/app/controllers/spree/api/addresses_controller.rb +0 -43
- data/app/controllers/spree/api/checkouts_controller.rb +0 -98
- data/app/controllers/spree/api/classifications_controller.rb +0 -18
- data/app/controllers/spree/api/countries_controller.rb +0 -23
- data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
- data/app/controllers/spree/api/images_controller.rb +0 -47
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
- data/app/controllers/spree/api/line_items_controller.rb +0 -69
- data/app/controllers/spree/api/option_types_controller.rb +0 -49
- data/app/controllers/spree/api/option_values_controller.rb +0 -58
- data/app/controllers/spree/api/orders_controller.rb +0 -130
- data/app/controllers/spree/api/payments_controller.rb +0 -80
- data/app/controllers/spree/api/product_properties_controller.rb +0 -72
- data/app/controllers/spree/api/products_controller.rb +0 -124
- data/app/controllers/spree/api/promotions_controller.rb +0 -26
- data/app/controllers/spree/api/properties_controller.rb +0 -70
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
- data/app/controllers/spree/api/shipments_controller.rb +0 -149
- data/app/controllers/spree/api/states_controller.rb +0 -38
- data/app/controllers/spree/api/stock_items_controller.rb +0 -75
- data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
- data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
- data/app/controllers/spree/api/stores_controller.rb +0 -55
- data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
- data/app/controllers/spree/api/taxons_controller.rb +0 -93
- data/app/controllers/spree/api/users_controller.rb +0 -56
- data/app/controllers/spree/api/variants_controller.rb +0 -73
- data/app/controllers/spree/api/zones_controller.rb +0 -49
- data/app/models/spree/option_value_decorator.rb +0 -9
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 619c0d865d3f6eb5fdbd68c17860e2e7a260452f
|
4
|
+
data.tar.gz: 15a80886dd571611fede3f469fd5bec77424eb5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0caf79058b10c7b724e0b5f8870b0dd4b93db16b1f48bfe4a1db7dc353eb9bdfb5c49d5bb5328e0dc50e1931cb233b3db1687be25af259956c1accb7831540
|
7
|
+
data.tar.gz: ae5ba6a9dce7d870b644f07967aa548b778f72fe7f2117e37a697506de91a97039c5dd8e4b1e3f009d38d2ea56acb183688b880b49f6d127fc0a5bbcc7a8caba
|
@@ -9,15 +9,14 @@ module Spree
|
|
9
9
|
|
10
10
|
attr_accessor :current_api_user
|
11
11
|
|
12
|
-
class_attribute :error_notifier
|
13
|
-
|
14
12
|
before_action :set_content_type
|
15
13
|
before_action :load_user
|
16
14
|
before_action :authorize_for_order, if: Proc.new { order_token.present? }
|
17
15
|
before_action :authenticate_user
|
18
16
|
before_action :load_user_roles
|
19
17
|
|
20
|
-
rescue_from
|
18
|
+
rescue_from ActionController::ParameterMissing, with: :error_during_processing
|
19
|
+
rescue_from ActiveRecord::RecordInvalid, with: :error_during_processing
|
21
20
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
22
21
|
rescue_from CanCan::AccessDenied, with: :unauthorized
|
23
22
|
rescue_from Spree::Core::GatewayError, with: :gateway_error
|
@@ -62,24 +61,20 @@ module Spree
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def authenticate_user
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
64
|
+
return if @current_api_user
|
65
|
+
|
66
|
+
if requires_authentication? && api_key.blank? && order_token.blank?
|
67
|
+
render "spree/api/errors/must_specify_api_key", status: 401 and return
|
68
|
+
elsif order_token.blank? && (requires_authentication? || api_key.present?)
|
69
|
+
render "spree/api/errors/invalid_api_key", status: 401 and return
|
70
|
+
else
|
71
|
+
# An anonymous user
|
72
|
+
@current_api_user = Spree.user_class.new
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
76
|
def load_user_roles
|
78
|
-
@current_user_roles =
|
79
|
-
@current_api_user.spree_roles.pluck(:name)
|
80
|
-
else
|
81
|
-
[]
|
82
|
-
end
|
77
|
+
@current_user_roles = @current_api_user ? @current_api_user.spree_roles.pluck(:name) : []
|
83
78
|
end
|
84
79
|
|
85
80
|
def unauthorized
|
@@ -90,10 +85,11 @@ module Spree
|
|
90
85
|
Rails.logger.error exception.message
|
91
86
|
Rails.logger.error exception.backtrace.join("\n")
|
92
87
|
|
93
|
-
|
88
|
+
unprocessable_entity(exception.message)
|
89
|
+
end
|
94
90
|
|
95
|
-
|
96
|
-
|
91
|
+
def unprocessable_entity(message)
|
92
|
+
render text: { exception: message }.to_json, status: 422
|
97
93
|
end
|
98
94
|
|
99
95
|
def gateway_error(exception)
|
@@ -115,7 +111,7 @@ module Spree
|
|
115
111
|
|
116
112
|
def invalid_resource!(resource)
|
117
113
|
@resource = resource
|
118
|
-
render "spree/api/errors/invalid_resource", :
|
114
|
+
render "spree/api/errors/invalid_resource", status: 422
|
119
115
|
end
|
120
116
|
|
121
117
|
def api_key
|
@@ -140,6 +136,9 @@ module Spree
|
|
140
136
|
unless params[:show_deleted]
|
141
137
|
scope = scope.not_deleted
|
142
138
|
end
|
139
|
+
unless params[:show_discontinued]
|
140
|
+
scope = scope.not_discontinued
|
141
|
+
end
|
143
142
|
else
|
144
143
|
scope = Product.accessible_by(current_ability, :read).active.includes(*product_includes)
|
145
144
|
end
|
@@ -152,7 +151,7 @@ module Spree
|
|
152
151
|
end
|
153
152
|
|
154
153
|
def product_includes
|
155
|
-
[
|
154
|
+
[:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]
|
156
155
|
end
|
157
156
|
|
158
157
|
def order_id
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class AddressesController < Spree::Api::BaseController
|
5
|
+
before_action :find_order
|
6
|
+
|
7
|
+
def show
|
8
|
+
authorize! :read, @order, order_token
|
9
|
+
@address = find_address
|
10
|
+
respond_with(@address)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
authorize! :update, @order, order_token
|
15
|
+
@address = find_address
|
16
|
+
|
17
|
+
if @address.update_attributes(address_params)
|
18
|
+
respond_with(@address, :default_template => :show)
|
19
|
+
else
|
20
|
+
invalid_resource!(@address)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def address_params
|
27
|
+
params.require(:address).permit(permitted_address_attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_order
|
31
|
+
@order = Spree::Order.find_by!(number: order_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_address
|
35
|
+
if @order.bill_address_id == params[:id].to_i
|
36
|
+
@order.bill_address
|
37
|
+
elsif @order.ship_address_id == params[:id].to_i
|
38
|
+
@order.ship_address
|
39
|
+
else
|
40
|
+
raise CanCan::AccessDenied
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class CheckoutsController < Spree::Api::BaseController
|
5
|
+
before_action :associate_user, only: :update
|
6
|
+
before_action :load_order_with_lock, only: [:next, :advance, :update]
|
7
|
+
|
8
|
+
include Spree::Core::ControllerHelpers::Auth
|
9
|
+
include Spree::Core::ControllerHelpers::Order
|
10
|
+
# This before_action comes from Spree::Core::ControllerHelpers::Order
|
11
|
+
skip_before_action :set_current_order
|
12
|
+
|
13
|
+
def next
|
14
|
+
authorize! :update, @order, order_token
|
15
|
+
@order.next!
|
16
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
|
17
|
+
rescue StateMachines::InvalidTransition
|
18
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
|
19
|
+
end
|
20
|
+
|
21
|
+
def advance
|
22
|
+
authorize! :update, @order, order_token
|
23
|
+
while @order.next; end
|
24
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
authorize! :update, @order, order_token
|
29
|
+
|
30
|
+
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
|
31
|
+
if current_api_user.has_spree_role?('admin') && user_id.present?
|
32
|
+
@order.associate_user!(Spree.user_class.find(user_id))
|
33
|
+
end
|
34
|
+
|
35
|
+
return if after_update_attributes
|
36
|
+
|
37
|
+
if @order.completed? || @order.next
|
38
|
+
state_callback(:after)
|
39
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/show')
|
40
|
+
else
|
41
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
invalid_resource!(@order)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def user_id
|
51
|
+
params[:order][:user_id] if params[:order]
|
52
|
+
end
|
53
|
+
|
54
|
+
def nested_params
|
55
|
+
map_nested_attributes_keys Order, params[:order] || {}
|
56
|
+
end
|
57
|
+
|
58
|
+
# Should be overriden if you have areas of your checkout that don't match
|
59
|
+
# up to a step within checkout_steps, such as a registration step
|
60
|
+
def skip_state_validation?
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
def load_order(lock = false)
|
65
|
+
@order = Spree::Order.lock(lock).find_by!(number: params[:id])
|
66
|
+
raise_insufficient_quantity and return if @order.insufficient_stock_lines.present?
|
67
|
+
@order.state = params[:state] if params[:state]
|
68
|
+
state_callback(:before)
|
69
|
+
end
|
70
|
+
|
71
|
+
def load_order_with_lock
|
72
|
+
load_order(true)
|
73
|
+
end
|
74
|
+
|
75
|
+
def raise_insufficient_quantity
|
76
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/insufficient_quantity')
|
77
|
+
end
|
78
|
+
|
79
|
+
def state_callback(before_or_after = :before)
|
80
|
+
method_name = :"#{before_or_after}_#{@order.state}"
|
81
|
+
send(method_name) if respond_to?(method_name, true)
|
82
|
+
end
|
83
|
+
|
84
|
+
def after_update_attributes
|
85
|
+
if nested_params && nested_params[:coupon_code].present?
|
86
|
+
handler = PromotionHandler::Coupon.new(@order).apply
|
87
|
+
|
88
|
+
if handler.error.present?
|
89
|
+
@coupon_message = handler.error
|
90
|
+
respond_with(@order, default_template: 'spree/api/v1/orders/could_not_apply_coupon')
|
91
|
+
return true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
97
|
+
def order_id
|
98
|
+
super || params[:id]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ClassificationsController < Spree::Api::BaseController
|
5
|
+
def update
|
6
|
+
authorize! :update, Product
|
7
|
+
authorize! :update, Taxon
|
8
|
+
classification = Spree::Classification.find_by(
|
9
|
+
product_id: params[:product_id],
|
10
|
+
taxon_id: params[:taxon_id]
|
11
|
+
)
|
12
|
+
# Because position we get back is 0-indexed.
|
13
|
+
# acts_as_list is 1-indexed.
|
14
|
+
classification.insert_at(params[:position].to_i + 1)
|
15
|
+
render nothing: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class CountriesController < Spree::Api::BaseController
|
5
|
+
skip_before_action :authenticate_user
|
6
|
+
|
7
|
+
def index
|
8
|
+
@countries = Country.accessible_by(current_ability, :read).ransack(params[:q]).result.
|
9
|
+
order('name ASC').
|
10
|
+
page(params[:page]).per(params[:per_page])
|
11
|
+
country = Country.order("updated_at ASC").last
|
12
|
+
if stale?(country)
|
13
|
+
respond_with(@countries)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def show
|
18
|
+
@country = Country.accessible_by(current_ability, :read).find(params[:id])
|
19
|
+
respond_with(@country)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class CreditCardsController < Spree::Api::BaseController
|
5
|
+
before_action :user
|
6
|
+
|
7
|
+
def index
|
8
|
+
@credit_cards = user
|
9
|
+
.credit_cards
|
10
|
+
.accessible_by(current_ability, :read)
|
11
|
+
.with_payment_profile
|
12
|
+
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
13
|
+
respond_with(@credit_cards)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def user
|
19
|
+
if params[:user_id].present?
|
20
|
+
@user ||= Spree::user_class.accessible_by(current_ability, :read).find(params[:user_id])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class ImagesController < Spree::Api::BaseController
|
5
|
+
def index
|
6
|
+
@images = scope.images.accessible_by(current_ability, :read)
|
7
|
+
respond_with(@images)
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
@image = Image.accessible_by(current_ability, :read).find(params[:id])
|
12
|
+
respond_with(@image)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
authorize! :create, Image
|
17
|
+
@image = scope.images.new(image_params)
|
18
|
+
if @image.save
|
19
|
+
respond_with(@image, status: 201, default_template: :show)
|
20
|
+
else
|
21
|
+
invalid_resource!(@image)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
@image = scope.images.accessible_by(current_ability, :update).find(params[:id])
|
27
|
+
if @image.update_attributes(image_params)
|
28
|
+
respond_with(@image, default_template: :show)
|
29
|
+
else
|
30
|
+
invalid_resource!(@image)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
@image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
|
36
|
+
@image.destroy
|
37
|
+
respond_with(@image, status: 204)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def image_params
|
43
|
+
params.require(:image).permit(permitted_image_attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def scope
|
47
|
+
if params[:product_id]
|
48
|
+
Spree::Product.friendly.find(params[:product_id])
|
49
|
+
elsif params[:variant_id]
|
50
|
+
Spree::Variant.find(params[:variant_id])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class InventoryUnitsController < Spree::Api::BaseController
|
5
|
+
before_action :prepare_event, only: :update
|
6
|
+
|
7
|
+
def show
|
8
|
+
@inventory_unit = inventory_unit
|
9
|
+
respond_with(@inventory_unit)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
authorize! :update, inventory_unit.order
|
14
|
+
|
15
|
+
inventory_unit.transaction do
|
16
|
+
if inventory_unit.update_attributes(inventory_unit_params)
|
17
|
+
fire
|
18
|
+
render :show, :status => 200
|
19
|
+
else
|
20
|
+
invalid_resource!(inventory_unit)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def inventory_unit
|
28
|
+
@inventory_unit ||= InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
|
29
|
+
end
|
30
|
+
|
31
|
+
def prepare_event
|
32
|
+
return unless @event = params[:fire]
|
33
|
+
|
34
|
+
can_event = "can_#{@event}?"
|
35
|
+
|
36
|
+
unless inventory_unit.respond_to?(can_event) &&
|
37
|
+
inventory_unit.send(can_event)
|
38
|
+
render :text => { :exception => "cannot transition to #{@event}" }.to_json,
|
39
|
+
:status => 200
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def fire
|
45
|
+
inventory_unit.send("#{@event}!") if @event
|
46
|
+
end
|
47
|
+
|
48
|
+
def inventory_unit_params
|
49
|
+
params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|