spree_api 4.4.0 → 4.5.0

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.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +10 -8
  3. data/app/controllers/spree/api/v2/platform/orders_controller.rb +1 -1
  4. data/app/controllers/spree/api/v2/platform/products_controller.rb +5 -1
  5. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +1 -1
  6. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +5 -1
  7. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +4 -0
  8. data/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb +35 -0
  9. data/app/models/concerns/spree/webhooks/has_webhooks.rb +31 -7
  10. data/app/models/spree/api/webhooks/product_decorator.rb +21 -2
  11. data/app/models/spree/webhooks/subscriber.rb +4 -0
  12. data/app/serializers/spree/api/v2/platform/cms_section_image_one_serializer.rb +9 -0
  13. data/app/serializers/spree/api/v2/platform/cms_section_image_three_serializer.rb +9 -0
  14. data/app/serializers/spree/api/v2/platform/cms_section_image_two_serializer.rb +9 -0
  15. data/app/serializers/spree/api/v2/platform/hero_image_serializer.rb +10 -0
  16. data/app/serializers/spree/api/v2/platform/image_gallery_serializer.rb +10 -0
  17. data/app/serializers/spree/api/v2/platform/side_by_side_image_serializer.rb +10 -0
  18. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -0
  19. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  20. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +3 -3
  21. data/app/serializers/spree/v2/storefront/order_serializer.rb +9 -0
  22. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
  23. data/app/serializers/spree/v2/storefront/product_serializer.rb +1 -1
  24. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -0
  25. data/app/serializers/spree/v2/storefront/store_serializer.rb +5 -10
  26. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  27. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  28. data/app/services/spree/webhooks/subscribers/queue_requests.rb +8 -2
  29. data/config/routes.rb +1 -120
  30. data/docs/v2/platform/index.yaml +1597 -998
  31. data/docs/v2/storefront/index.yaml +357 -33
  32. data/lib/spree/api/configuration.rb +11 -0
  33. data/lib/spree/api/dependencies.rb +165 -0
  34. data/lib/spree/api/engine.rb +5 -16
  35. data/lib/spree/api/testing_support/v2/platform_contexts.rb +0 -1
  36. data/lib/spree/api.rb +0 -4
  37. data/lib/spree_api.rb +0 -1
  38. data/spree_api.gemspec +0 -2
  39. metadata +16 -177
  40. data/app/controllers/spree/api/base_controller.rb +0 -171
  41. data/app/controllers/spree/api/v1/addresses_controller.rb +0 -46
  42. data/app/controllers/spree/api/v1/checkouts_controller.rb +0 -106
  43. data/app/controllers/spree/api/v1/classifications_controller.rb +0 -21
  44. data/app/controllers/spree/api/v1/countries_controller.rb +0 -22
  45. data/app/controllers/spree/api/v1/credit_cards_controller.rb +0 -26
  46. data/app/controllers/spree/api/v1/customer_returns_controller.rb +0 -25
  47. data/app/controllers/spree/api/v1/images_controller.rb +0 -58
  48. data/app/controllers/spree/api/v1/inventory_units_controller.rb +0 -54
  49. data/app/controllers/spree/api/v1/line_items_controller.rb +0 -70
  50. data/app/controllers/spree/api/v1/option_types_controller.rb +0 -60
  51. data/app/controllers/spree/api/v1/option_values_controller.rb +0 -62
  52. data/app/controllers/spree/api/v1/orders_controller.rb +0 -160
  53. data/app/controllers/spree/api/v1/payments_controller.rb +0 -82
  54. data/app/controllers/spree/api/v1/product_properties_controller.rb +0 -73
  55. data/app/controllers/spree/api/v1/products_controller.rb +0 -131
  56. data/app/controllers/spree/api/v1/promotions_controller.rb +0 -30
  57. data/app/controllers/spree/api/v1/properties_controller.rb +0 -70
  58. data/app/controllers/spree/api/v1/reimbursements_controller.rb +0 -25
  59. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -70
  60. data/app/controllers/spree/api/v1/shipments_controller.rb +0 -196
  61. data/app/controllers/spree/api/v1/states_controller.rb +0 -36
  62. data/app/controllers/spree/api/v1/stock_items_controller.rb +0 -82
  63. data/app/controllers/spree/api/v1/stock_locations_controller.rb +0 -53
  64. data/app/controllers/spree/api/v1/stock_movements_controller.rb +0 -45
  65. data/app/controllers/spree/api/v1/stores_controller.rb +0 -56
  66. data/app/controllers/spree/api/v1/taxonomies_controller.rb +0 -67
  67. data/app/controllers/spree/api/v1/taxons_controller.rb +0 -100
  68. data/app/controllers/spree/api/v1/users_controller.rb +0 -97
  69. data/app/controllers/spree/api/v1/variants_controller.rb +0 -81
  70. data/app/controllers/spree/api/v1/zones_controller.rb +0 -55
  71. data/app/helpers/spree/api/api_helpers.rb +0 -190
  72. data/app/models/spree/api_configuration.rb +0 -10
  73. data/app/views/spree/api/errors/gateway_error.rabl +0 -2
  74. data/app/views/spree/api/errors/invalid_api_key.rabl +0 -2
  75. data/app/views/spree/api/errors/invalid_resource.rabl +0 -3
  76. data/app/views/spree/api/errors/must_specify_api_key.rabl +0 -2
  77. data/app/views/spree/api/errors/not_found.rabl +0 -2
  78. data/app/views/spree/api/errors/unauthorized.rabl +0 -2
  79. data/app/views/spree/api/v1/addresses/show.rabl +0 -10
  80. data/app/views/spree/api/v1/adjustments/show.rabl +0 -4
  81. data/app/views/spree/api/v1/countries/index.rabl +0 -7
  82. data/app/views/spree/api/v1/countries/show.rabl +0 -5
  83. data/app/views/spree/api/v1/credit_cards/index.rabl +0 -7
  84. data/app/views/spree/api/v1/credit_cards/show.rabl +0 -3
  85. data/app/views/spree/api/v1/customer_returns/index.rabl +0 -7
  86. data/app/views/spree/api/v1/images/index.rabl +0 -4
  87. data/app/views/spree/api/v1/images/new.rabl +0 -3
  88. data/app/views/spree/api/v1/images/show.rabl +0 -6
  89. data/app/views/spree/api/v1/inventory_units/show.rabl +0 -2
  90. data/app/views/spree/api/v1/line_items/new.rabl +0 -3
  91. data/app/views/spree/api/v1/line_items/show.rabl +0 -14
  92. data/app/views/spree/api/v1/option_types/index.rabl +0 -3
  93. data/app/views/spree/api/v1/option_types/new.rabl +0 -3
  94. data/app/views/spree/api/v1/option_types/show.rabl +0 -5
  95. data/app/views/spree/api/v1/option_values/index.rabl +0 -3
  96. data/app/views/spree/api/v1/option_values/new.rabl +0 -3
  97. data/app/views/spree/api/v1/option_values/show.rabl +0 -2
  98. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  99. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  100. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  101. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  102. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +0 -2
  103. data/app/views/spree/api/v1/orders/could_not_transition.rabl +0 -3
  104. data/app/views/spree/api/v1/orders/index.rabl +0 -7
  105. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +0 -2
  106. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +0 -2
  107. data/app/views/spree/api/v1/orders/mine.rabl +0 -9
  108. data/app/views/spree/api/v1/orders/order.rabl +0 -10
  109. data/app/views/spree/api/v1/orders/payment.rabl +0 -3
  110. data/app/views/spree/api/v1/orders/show.rabl +0 -51
  111. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +0 -2
  112. data/app/views/spree/api/v1/payments/index.rabl +0 -7
  113. data/app/views/spree/api/v1/payments/new.rabl +0 -5
  114. data/app/views/spree/api/v1/payments/show.rabl +0 -2
  115. data/app/views/spree/api/v1/payments/update_forbidden.rabl +0 -2
  116. data/app/views/spree/api/v1/product_properties/index.rabl +0 -7
  117. data/app/views/spree/api/v1/product_properties/new.rabl +0 -2
  118. data/app/views/spree/api/v1/product_properties/show.rabl +0 -2
  119. data/app/views/spree/api/v1/products/index.rabl +0 -9
  120. data/app/views/spree/api/v1/products/new.rabl +0 -3
  121. data/app/views/spree/api/v1/products/product.rabl +0 -1
  122. data/app/views/spree/api/v1/products/show.rabl +0 -36
  123. data/app/views/spree/api/v1/promotions/handler.rabl +0 -5
  124. data/app/views/spree/api/v1/promotions/show.rabl +0 -2
  125. data/app/views/spree/api/v1/properties/index.rabl +0 -7
  126. data/app/views/spree/api/v1/properties/new.rabl +0 -2
  127. data/app/views/spree/api/v1/properties/show.rabl +0 -2
  128. data/app/views/spree/api/v1/reimbursements/index.rabl +0 -7
  129. data/app/views/spree/api/v1/return_authorizations/index.rabl +0 -7
  130. data/app/views/spree/api/v1/return_authorizations/new.rabl +0 -3
  131. data/app/views/spree/api/v1/return_authorizations/show.rabl +0 -2
  132. data/app/views/spree/api/v1/shared/stock_location_required.rabl +0 -2
  133. data/app/views/spree/api/v1/shipments/big.rabl +0 -48
  134. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +0 -2
  135. data/app/views/spree/api/v1/shipments/mine.rabl +0 -9
  136. data/app/views/spree/api/v1/shipments/show.rabl +0 -32
  137. data/app/views/spree/api/v1/shipments/small.rabl +0 -37
  138. data/app/views/spree/api/v1/shipping_rates/show.rabl +0 -2
  139. data/app/views/spree/api/v1/states/index.rabl +0 -12
  140. data/app/views/spree/api/v1/states/show.rabl +0 -2
  141. data/app/views/spree/api/v1/stock_items/index.rabl +0 -7
  142. data/app/views/spree/api/v1/stock_items/show.rabl +0 -5
  143. data/app/views/spree/api/v1/stock_locations/index.rabl +0 -7
  144. data/app/views/spree/api/v1/stock_locations/show.rabl +0 -8
  145. data/app/views/spree/api/v1/stock_movements/index.rabl +0 -7
  146. data/app/views/spree/api/v1/stock_movements/show.rabl +0 -5
  147. data/app/views/spree/api/v1/stores/index.rabl +0 -4
  148. data/app/views/spree/api/v1/stores/show.rabl +0 -2
  149. data/app/views/spree/api/v1/tags/index.rabl +0 -9
  150. data/app/views/spree/api/v1/taxonomies/index.rabl +0 -7
  151. data/app/views/spree/api/v1/taxonomies/jstree.rabl +0 -7
  152. data/app/views/spree/api/v1/taxonomies/nested.rabl +0 -11
  153. data/app/views/spree/api/v1/taxonomies/new.rabl +0 -3
  154. data/app/views/spree/api/v1/taxonomies/show.rabl +0 -15
  155. data/app/views/spree/api/v1/taxons/index.rabl +0 -10
  156. data/app/views/spree/api/v1/taxons/jstree.rabl +0 -7
  157. data/app/views/spree/api/v1/taxons/new.rabl +0 -3
  158. data/app/views/spree/api/v1/taxons/show.rabl +0 -6
  159. data/app/views/spree/api/v1/taxons/taxons.rabl +0 -5
  160. data/app/views/spree/api/v1/users/index.rabl +0 -7
  161. data/app/views/spree/api/v1/users/new.rabl +0 -3
  162. data/app/views/spree/api/v1/users/show.rabl +0 -11
  163. data/app/views/spree/api/v1/variants/big.rabl +0 -14
  164. data/app/views/spree/api/v1/variants/index.rabl +0 -9
  165. data/app/views/spree/api/v1/variants/new.rabl +0 -2
  166. data/app/views/spree/api/v1/variants/show.rabl +0 -3
  167. data/app/views/spree/api/v1/variants/small.rabl +0 -18
  168. data/app/views/spree/api/v1/zones/index.rabl +0 -7
  169. data/app/views/spree/api/v1/zones/show.rabl +0 -6
  170. data/config/initializers/rabl.rb +0 -9
  171. data/lib/spree/api/api_dependencies.rb +0 -163
  172. data/lib/spree/api/controller_setup.rb +0 -19
  173. data/lib/spree/api/responders/rabl_template.rb +0 -28
  174. data/lib/spree/api/responders.rb +0 -11
  175. data/lib/spree/api/testing_support/helpers.rb +0 -44
  176. data/lib/spree/api/testing_support/setup.rb +0 -16
@@ -1,70 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class ReturnAuthorizationsController < Spree::Api::BaseController
5
- def create
6
- authorize! :create, ReturnAuthorization
7
- @return_authorization = order.return_authorizations.build(return_authorization_params)
8
- if @return_authorization.save
9
- respond_with(@return_authorization, status: 201, default_template: :show)
10
- else
11
- invalid_resource!(@return_authorization)
12
- end
13
- end
14
-
15
- def destroy
16
- @return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
17
- @return_authorization.destroy
18
- respond_with(@return_authorization, status: 204)
19
- end
20
-
21
- def index
22
- authorize! :admin, ReturnAuthorization
23
- @return_authorizations = order.return_authorizations.accessible_by(current_ability).
24
- ransack(params[:q]).result.
25
- page(params[:page]).per(params[:per_page])
26
- respond_with(@return_authorizations)
27
- end
28
-
29
- def new
30
- authorize! :admin, ReturnAuthorization
31
- end
32
-
33
- def show
34
- authorize! :admin, ReturnAuthorization
35
- @return_authorization = order.return_authorizations.accessible_by(current_ability, :show).find(params[:id])
36
- respond_with(@return_authorization)
37
- end
38
-
39
- def update
40
- @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
41
- if @return_authorization.update(return_authorization_params)
42
- respond_with(@return_authorization, default_template: :show)
43
- else
44
- invalid_resource!(@return_authorization)
45
- end
46
- end
47
-
48
- def cancel
49
- @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
50
- if @return_authorization.cancel
51
- respond_with @return_authorization, default_template: :show
52
- else
53
- invalid_resource!(@return_authorization)
54
- end
55
- end
56
-
57
- private
58
-
59
- def order
60
- @order ||= Spree::Order.find_by!(number: order_id)
61
- authorize! :show, @order
62
- end
63
-
64
- def return_authorization_params
65
- params.require(:return_authorization).permit(permitted_return_authorization_attributes)
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,196 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class ShipmentsController < Spree::Api::BaseController
5
- before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
6
- before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]
7
-
8
- def mine
9
- if current_api_user.persisted?
10
- @shipments = Spree::Shipment.
11
- reverse_chronological.
12
- joins(:order).
13
- where(spree_orders: { user_id: current_api_user.id }).
14
- includes(mine_includes).
15
- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
16
- else
17
- render 'spree/api/errors/unauthorized', status: :unauthorized
18
- end
19
- end
20
-
21
- def create
22
- @order = Spree::Order.find_by!(number: params.fetch(:shipment).fetch(:order_id))
23
- authorize! :show, @order
24
- authorize! :create, Shipment
25
- quantity = params[:quantity].to_i
26
- @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
27
-
28
- @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: @order,
29
- variant: variant,
30
- quantity: quantity,
31
- options: { shipment: @shipment }).value
32
-
33
- respond_with(@shipment.reload, default_template: :show)
34
- end
35
-
36
- def update
37
- @shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
38
- @shipment.update_attributes_and_order(shipment_params)
39
-
40
- respond_with(@shipment.reload, default_template: :show)
41
- end
42
-
43
- def ready
44
- unless @shipment.ready?
45
- if @shipment.can_ready?
46
- @shipment.ready!
47
- else
48
- render 'spree/api/v1/shipments/cannot_ready_shipment', status: 422 and return
49
- end
50
- end
51
- respond_with(@shipment, default_template: :show)
52
- end
53
-
54
- def ship
55
- @shipment.ship! unless @shipment.shipped?
56
- respond_with(@shipment, default_template: :show)
57
- end
58
-
59
- def add
60
- quantity = params[:quantity].to_i
61
-
62
- Spree::Dependencies.cart_add_item_service.constantize.call(order: @shipment.order,
63
- variant: variant,
64
- quantity: quantity,
65
- options: { shipment: @shipment })
66
-
67
- respond_with(@shipment, default_template: :show)
68
- end
69
-
70
- def remove
71
- quantity = if params.key?(:quantity)
72
- params[:quantity].to_i
73
- else
74
- @shipment.inventory_units_for(variant).sum(:quantity)
75
- end
76
-
77
- Spree::Dependencies.cart_remove_item_service.constantize.call(order: @shipment.order,
78
- variant: variant,
79
- quantity: quantity,
80
- options: { shipment: @shipment })
81
-
82
- if @shipment.inventory_units.any?
83
- @shipment.reload
84
- else
85
- @shipment.destroy!
86
- end
87
-
88
- respond_with(@shipment, default_template: :show)
89
- end
90
-
91
- def transfer_to_location
92
- @stock_location = Spree::StockLocation.find(params[:stock_location_id])
93
-
94
- unless @quantity > 0
95
- unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n #{Spree.t(:negative_quantity, scope: 'api')}")
96
- return
97
- end
98
-
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
106
- end
107
-
108
- def transfer_to_shipment
109
- @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
110
-
111
- error =
112
- if @quantity < 0 && @target_shipment == @original_shipment
113
- "#{Spree.t(:negative_quantity, scope: 'api')}, \n#{Spree.t('wrong_shipment_target', scope: 'api')}"
114
- elsif @target_shipment == @original_shipment
115
- Spree.t(:wrong_shipment_target, scope: 'api')
116
- elsif @quantity < 0
117
- Spree.t(:negative_quantity, scope: 'api')
118
- end
119
-
120
- if error
121
- unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{error}")
122
- else
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
130
- end
131
- end
132
-
133
- private
134
-
135
- def load_transfer_params
136
- @original_shipment = Spree::Shipment.find_by!(number: params[:original_shipment_number])
137
- @variant = Spree::Variant.find(params[:variant_id])
138
- @quantity = params[:quantity].to_i
139
- authorize! :show, @original_shipment
140
- authorize! :create, Shipment
141
- end
142
-
143
- def find_and_update_shipment
144
- @shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
145
- @shipment.update(shipment_params)
146
- @shipment.reload
147
- end
148
-
149
- def shipment_params
150
- if params[:shipment] && !params[:shipment].empty?
151
- params.require(:shipment).permit(permitted_shipment_attributes)
152
- else
153
- {}
154
- end
155
- end
156
-
157
- def variant
158
- @variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))
159
- end
160
-
161
- def mine_includes
162
- {
163
- order: {
164
- bill_address: {
165
- state: {},
166
- country: {}
167
- },
168
- ship_address: {
169
- state: {},
170
- country: {}
171
- },
172
- adjustments: {},
173
- payments: {
174
- order: {},
175
- payment_method: {}
176
- }
177
- },
178
- inventory_units: {
179
- line_item: {
180
- product: {},
181
- variant: {}
182
- },
183
- variant: {
184
- product: {},
185
- default_price: {},
186
- option_values: {
187
- option_type: {}
188
- }
189
- }
190
- }
191
- }
192
- end
193
- end
194
- end
195
- end
196
- end
@@ -1,36 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class StatesController < Spree::Api::BaseController
5
- skip_before_action :authenticate_user
6
-
7
- def index
8
- @states = scope.ransack(params[:q]).result.includes(:country)
9
-
10
- if params[:page] || params[:per_page]
11
- @states = @states.page(params[:page]).per(params[:per_page])
12
- end
13
-
14
- state = @states.last
15
- respond_with(@states) if stale?(state)
16
- end
17
-
18
- def show
19
- @state = scope.find(params[:id])
20
- respond_with(@state)
21
- end
22
-
23
- private
24
-
25
- def scope
26
- if params[:country_id]
27
- @country = Country.accessible_by(current_ability, :show).find(params[:country_id])
28
- @country.states.accessible_by(current_ability).order('name ASC')
29
- else
30
- State.accessible_by(current_ability).order('name ASC')
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,82 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class StockItemsController < Spree::Api::BaseController
5
- before_action :stock_location, except: [:update, :destroy]
6
-
7
- def index
8
- @stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
9
- respond_with(@stock_items)
10
- end
11
-
12
- def show
13
- @stock_item = scope.find(params[:id])
14
- respond_with(@stock_item)
15
- end
16
-
17
- def create
18
- authorize! :create, StockItem
19
-
20
- count_on_hand = 0
21
- if params[:stock_item].key?(:count_on_hand)
22
- count_on_hand = params[:stock_item][:count_on_hand].to_i
23
- end
24
-
25
- @stock_item = scope.new(stock_item_params)
26
- if @stock_item.save
27
- @stock_item.adjust_count_on_hand(count_on_hand)
28
- respond_with(@stock_item, status: 201, default_template: :show)
29
- else
30
- invalid_resource!(@stock_item)
31
- end
32
- end
33
-
34
- def update
35
- @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
36
-
37
- if params[:stock_item].key?(:backorderable)
38
- @stock_item.backorderable = params[:stock_item][:backorderable]
39
- @stock_item.save
40
- end
41
-
42
- count_on_hand = 0
43
- if params[:stock_item].key?(:count_on_hand)
44
- count_on_hand = params[:stock_item][:count_on_hand].to_i
45
- params[:stock_item].delete(:count_on_hand)
46
- end
47
-
48
- updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
49
- : @stock_item.adjust_count_on_hand(count_on_hand)
50
-
51
- if updated
52
- respond_with(@stock_item, status: 200, default_template: :show)
53
- else
54
- invalid_resource!(@stock_item)
55
- end
56
- end
57
-
58
- def destroy
59
- @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
60
- @stock_item.destroy
61
- respond_with(@stock_item, status: 204)
62
- end
63
-
64
- private
65
-
66
- def stock_location
67
- render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
68
- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])
69
- end
70
-
71
- def scope
72
- includes = { variant: [{ option_values: :option_type }, :product] }
73
- @stock_location.stock_items.accessible_by(current_ability, :show).includes(includes)
74
- end
75
-
76
- def stock_item_params
77
- params.require(:stock_item).permit(permitted_stock_item_attributes)
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,53 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class StockLocationsController < Spree::Api::BaseController
5
- def index
6
- authorize! :index, StockLocation
7
- @stock_locations = StockLocation.accessible_by(current_ability).order('name ASC').
8
- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
9
- respond_with(@stock_locations)
10
- end
11
-
12
- def show
13
- respond_with(stock_location)
14
- end
15
-
16
- def create
17
- authorize! :create, StockLocation
18
- @stock_location = StockLocation.new(stock_location_params)
19
- if @stock_location.save
20
- respond_with(@stock_location, status: 201, default_template: :show)
21
- else
22
- invalid_resource!(@stock_location)
23
- end
24
- end
25
-
26
- def update
27
- authorize! :update, stock_location
28
- if stock_location.update(stock_location_params)
29
- respond_with(stock_location, status: 200, default_template: :show)
30
- else
31
- invalid_resource!(stock_location)
32
- end
33
- end
34
-
35
- def destroy
36
- authorize! :destroy, stock_location
37
- stock_location.destroy
38
- respond_with(stock_location, status: 204)
39
- end
40
-
41
- private
42
-
43
- def stock_location
44
- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:id])
45
- end
46
-
47
- def stock_location_params
48
- params.require(:stock_location).permit(permitted_stock_location_attributes)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,45 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class StockMovementsController < Spree::Api::BaseController
5
- before_action :stock_location, except: [:update, :destroy]
6
-
7
- def index
8
- authorize! :index, StockMovement
9
- @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
- respond_with(@stock_movements)
11
- end
12
-
13
- def show
14
- @stock_movement = scope.find(params[:id])
15
- respond_with(@stock_movement)
16
- end
17
-
18
- def create
19
- authorize! :create, StockMovement
20
- @stock_movement = scope.new(stock_movement_params)
21
- if @stock_movement.save
22
- respond_with(@stock_movement, status: 201, default_template: :show)
23
- else
24
- invalid_resource!(@stock_movement)
25
- end
26
- end
27
-
28
- private
29
-
30
- def stock_location
31
- render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
32
- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])
33
- end
34
-
35
- def scope
36
- @stock_location.stock_movements.accessible_by(current_ability, :show)
37
- end
38
-
39
- def stock_movement_params
40
- params.require(:stock_movement).permit(permitted_stock_movement_attributes)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,56 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class StoresController < Spree::Api::BaseController
5
- before_action :get_store, except: [:index, :create]
6
-
7
- def index
8
- authorize! :index, Store
9
- @stores = Store.accessible_by(current_ability).all
10
- respond_with(@stores)
11
- end
12
-
13
- def create
14
- authorize! :create, Store
15
- @store = Store.new(store_params)
16
- @store.code = params[:store][:code]
17
- if @store.save
18
- respond_with(@store, status: 201, default_template: :show)
19
- else
20
- invalid_resource!(@store)
21
- end
22
- end
23
-
24
- def update
25
- authorize! :update, @store
26
- if @store.update(store_params)
27
- respond_with(@store, status: 200, default_template: :show)
28
- else
29
- invalid_resource!(@store)
30
- end
31
- end
32
-
33
- def show
34
- authorize! :show, @store
35
- respond_with(@store)
36
- end
37
-
38
- def destroy
39
- authorize! :destroy, @store
40
- @store.destroy
41
- respond_with(@store, status: 204)
42
- end
43
-
44
- private
45
-
46
- def get_store
47
- @store = Store.find(params[:id])
48
- end
49
-
50
- def store_params
51
- params.require(:store).permit(permitted_store_attributes)
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,67 +0,0 @@
1
- module Spree
2
- module Api
3
- module V1
4
- class TaxonomiesController < Spree::Api::BaseController
5
- def index
6
- respond_with(taxonomies)
7
- end
8
-
9
- def show
10
- respond_with(taxonomy)
11
- end
12
-
13
- # Because JSTree wants parameters in a *slightly* different format
14
- def jstree
15
- show
16
- end
17
-
18
- def new; end
19
-
20
- def create
21
- authorize! :create, Taxonomy
22
- @taxonomy = current_store.taxonomies.new(taxonomy_params)
23
- if @taxonomy.save
24
- respond_with(@taxonomy, status: 201, default_template: :show)
25
- else
26
- invalid_resource!(@taxonomy)
27
- end
28
- end
29
-
30
- def update
31
- authorize! :update, taxonomy
32
- if taxonomy.update(taxonomy_params)
33
- respond_with(taxonomy, status: 200, default_template: :show)
34
- else
35
- invalid_resource!(taxonomy)
36
- end
37
- end
38
-
39
- def destroy
40
- authorize! :destroy, taxonomy
41
- taxonomy.destroy
42
- respond_with(taxonomy, status: 204)
43
- end
44
-
45
- private
46
-
47
- def taxonomies
48
- @taxonomies = Taxonomy.accessible_by(current_ability).order('name').includes(root: :children).
49
- ransack(params[:q]).result.
50
- page(params[:page]).per(params[:per_page])
51
- end
52
-
53
- def taxonomy
54
- @taxonomy ||= Taxonomy.accessible_by(current_ability, :show).find(params[:id])
55
- end
56
-
57
- def taxonomy_params
58
- if params[:taxonomy] && !params[:taxonomy].empty?
59
- params.require(:taxonomy).permit(permitted_taxonomy_attributes)
60
- else
61
- {}
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end