solidus_api 2.3.1 → 2.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +9 -12
  3. data/app/controllers/spree/api/checkouts_controller.rb +3 -5
  4. data/app/controllers/spree/api/orders_controller.rb +2 -12
  5. data/app/controllers/spree/api/payments_controller.rb +0 -1
  6. data/app/controllers/spree/api/resource_controller.rb +2 -0
  7. data/app/controllers/spree/api/shipments_controller.rb +17 -6
  8. data/app/controllers/spree/api/stock_items_controller.rb +6 -0
  9. data/app/helpers/spree/api/api_helpers.rb +3 -4
  10. data/app/views/.rubocop.yml +4 -0
  11. data/app/views/spree/api/address_books/show.json.jbuilder +11 -0
  12. data/app/views/spree/api/addresses/_address.json.jbuilder +17 -0
  13. data/app/views/spree/api/addresses/show.json.jbuilder +1 -0
  14. data/app/views/spree/api/adjustments/_adjustment.json.jbuilder +4 -0
  15. data/app/views/spree/api/config/money.json.jbuilder +1 -0
  16. data/app/views/spree/api/config/show.json.jbuilder +2 -0
  17. data/app/views/spree/api/countries/index.json.jbuilder +2 -0
  18. data/app/views/spree/api/countries/show.json.jbuilder +4 -0
  19. data/app/views/spree/api/credit_cards/_credit_card.json.jbuilder +10 -0
  20. data/app/views/spree/api/credit_cards/index.json.jbuilder +4 -0
  21. data/app/views/spree/api/credit_cards/show.json.jbuilder +1 -0
  22. data/app/views/spree/api/errors/delete_restriction.json.jbuilder +1 -0
  23. data/app/views/spree/api/errors/gateway_error.json.jbuilder +1 -0
  24. data/app/views/spree/api/errors/invalid_api_key.json.jbuilder +1 -0
  25. data/app/views/spree/api/errors/invalid_resource.json.jbuilder +2 -0
  26. data/app/views/spree/api/errors/must_specify_api_key.json.jbuilder +1 -0
  27. data/app/views/spree/api/errors/not_found.json.jbuilder +1 -0
  28. data/app/views/spree/api/errors/unauthorized.json.jbuilder +1 -0
  29. data/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +1 -0
  30. data/app/views/spree/api/images/_image.json.jbuilder +5 -0
  31. data/app/views/spree/api/images/index.json.jbuilder +3 -0
  32. data/app/views/spree/api/images/show.json.jbuilder +1 -0
  33. data/app/views/spree/api/inventory_units/show.json.jbuilder +1 -0
  34. data/app/views/spree/api/line_items/_line_item.json.jbuilder +16 -0
  35. data/app/views/spree/api/line_items/new.json.jbuilder +2 -0
  36. data/app/views/spree/api/line_items/show.json.jbuilder +1 -0
  37. data/app/views/spree/api/option_types/_option_type.json.jbuilder +4 -0
  38. data/app/views/spree/api/option_types/index.json.jbuilder +3 -0
  39. data/app/views/spree/api/option_types/show.json.jbuilder +1 -0
  40. data/app/views/spree/api/option_values/_option_value.json.jbuilder +1 -0
  41. data/app/views/spree/api/option_values/index.json.jbuilder +3 -0
  42. data/app/views/spree/api/option_values/show.json.jbuilder +1 -0
  43. data/app/views/spree/api/orders/_big.json.jbuilder +49 -0
  44. data/app/views/spree/api/orders/_order.json.jbuilder +10 -0
  45. data/app/views/spree/api/orders/could_not_apply_coupon.json.jbuilder +1 -0
  46. data/app/views/spree/api/orders/could_not_transition.json.jbuilder +2 -0
  47. data/app/views/spree/api/orders/expected_total_mismatch.json.jbuilder +1 -0
  48. data/app/views/spree/api/orders/index.json.jbuilder +4 -0
  49. data/app/views/spree/api/orders/invalid_shipping_method.json.jbuilder +1 -0
  50. data/app/views/spree/api/orders/mine.json.jbuilder +4 -0
  51. data/app/views/spree/api/orders/show.json.jbuilder +1 -0
  52. data/app/views/spree/api/payments/credit_over_limit.json.jbuilder +1 -0
  53. data/app/views/spree/api/payments/index.json.jbuilder +2 -0
  54. data/app/views/spree/api/payments/new.json.jbuilder +4 -0
  55. data/app/views/spree/api/payments/show.json.jbuilder +1 -0
  56. data/app/views/spree/api/payments/update_forbidden.json.jbuilder +1 -0
  57. data/app/views/spree/api/product_properties/index.json.jbuilder +4 -0
  58. data/app/views/spree/api/product_properties/new.json.jbuilder +2 -0
  59. data/app/views/spree/api/product_properties/show.json.jbuilder +1 -0
  60. data/app/views/spree/api/products/_product.json.jbuilder +34 -0
  61. data/app/views/spree/api/products/index.json.jbuilder +4 -0
  62. data/app/views/spree/api/products/new.json.jbuilder +2 -0
  63. data/app/views/spree/api/products/show.json.jbuilder +1 -0
  64. data/app/views/spree/api/promotions/handler.json.jbuilder +4 -0
  65. data/app/views/spree/api/promotions/show.json.jbuilder +1 -0
  66. data/app/views/spree/api/properties/index.json.jbuilder +4 -0
  67. data/app/views/spree/api/properties/new.json.jbuilder +2 -0
  68. data/app/views/spree/api/properties/show.json.jbuilder +1 -0
  69. data/app/views/spree/api/return_authorizations/index.json.jbuilder +4 -0
  70. data/app/views/spree/api/return_authorizations/new.json.jbuilder +2 -0
  71. data/app/views/spree/api/return_authorizations/show.json.jbuilder +1 -0
  72. data/app/views/spree/api/shared/_pagination.json.jbuilder +5 -0
  73. data/app/views/spree/api/shipments/_big.json.jbuilder +51 -0
  74. data/app/views/spree/api/shipments/_small.json.jbuilder +32 -0
  75. data/app/views/spree/api/shipments/cannot_ready_shipment.json.jbuilder +1 -0
  76. data/app/views/spree/api/shipments/mine.json.jbuilder +4 -0
  77. data/app/views/spree/api/shipments/show.json.jbuilder +31 -0
  78. data/app/views/spree/api/shipping_rates/_shipping_rate.json.jbuilder +2 -0
  79. data/app/views/spree/api/states/index.json.jbuilder +5 -0
  80. data/app/views/spree/api/states/show.json.jbuilder +1 -0
  81. data/app/views/spree/api/stock_items/_stock_item.json.jbuilder +4 -0
  82. data/app/views/spree/api/stock_items/index.json.jbuilder +4 -0
  83. data/app/views/spree/api/stock_items/show.json.jbuilder +1 -0
  84. data/app/views/spree/api/stock_locations/_stock_location.json.jbuilder +15 -0
  85. data/app/views/spree/api/stock_locations/index.json.jbuilder +4 -0
  86. data/app/views/spree/api/stock_locations/show.json.jbuilder +1 -0
  87. data/app/views/spree/api/stock_movements/_stock_movement.json.jbuilder +4 -0
  88. data/app/views/spree/api/stock_movements/index.json.jbuilder +4 -0
  89. data/app/views/spree/api/stock_movements/show.json.jbuilder +1 -0
  90. data/app/views/spree/api/stock_transfers/receive.json.jbuilder +4 -0
  91. data/app/views/spree/api/store_credit_events/mine.json.jbuilder +5 -0
  92. data/app/views/spree/api/stores/index.json.jbuilder +1 -0
  93. data/app/views/spree/api/stores/show.json.jbuilder +1 -0
  94. data/app/views/spree/api/taxonomies/_nested.json.jbuilder +8 -0
  95. data/app/views/spree/api/taxonomies/_taxonomy.json.jbuilder +11 -0
  96. data/app/views/spree/api/taxonomies/index.json.jbuilder +4 -0
  97. data/app/views/spree/api/taxonomies/jstree.json.jbuilder +6 -0
  98. data/app/views/spree/api/taxonomies/new.json.jbuilder +2 -0
  99. data/app/views/spree/api/taxonomies/show.json.jbuilder +1 -0
  100. data/app/views/spree/api/taxons/_taxon.json.jbuilder +2 -0
  101. data/app/views/spree/api/taxons/_taxons.json.jbuilder +4 -0
  102. data/app/views/spree/api/taxons/index.json.jbuilder +7 -0
  103. data/app/views/spree/api/taxons/jstree.json.jbuilder +8 -0
  104. data/app/views/spree/api/taxons/new.json.jbuilder +2 -0
  105. data/app/views/spree/api/taxons/show.json.jbuilder +1 -0
  106. data/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +5 -0
  107. data/app/views/spree/api/transfer_items/show.json.jbuilder +1 -0
  108. data/app/views/spree/api/users/_user.json.jbuilder +15 -0
  109. data/app/views/spree/api/users/index.json.jbuilder +4 -0
  110. data/app/views/spree/api/users/new.json.jbuilder +2 -0
  111. data/app/views/spree/api/users/show.json.jbuilder +1 -0
  112. data/app/views/spree/api/variants/_big.json.jbuilder +13 -0
  113. data/app/views/spree/api/variants/_small.json.jbuilder +16 -0
  114. data/app/views/spree/api/variants/index.json.jbuilder +4 -0
  115. data/app/views/spree/api/variants/new.json.jbuilder +2 -0
  116. data/app/views/spree/api/variants/show.json.jbuilder +1 -0
  117. data/app/views/spree/api/zones/_zone.json.jbuilder +4 -0
  118. data/app/views/spree/api/zones/index.json.jbuilder +4 -0
  119. data/app/views/spree/api/zones/show.json.jbuilder +1 -0
  120. data/config/locales/en.yml +1 -0
  121. data/lib/spree/api/engine.rb +0 -14
  122. data/lib/spree/api.rb +1 -1
  123. data/lib/spree_api.rb +1 -0
  124. data/solidus_api.gemspec +3 -1
  125. data/spec/controllers/spree/api/base_controller_spec.rb +0 -56
  126. data/spec/requests/spree/api/checkouts_controller_spec.rb +8 -13
  127. data/spec/requests/spree/api/orders_controller_spec.rb +7 -60
  128. data/spec/requests/spree/api/payments_controller_spec.rb +0 -11
  129. data/spec/requests/spree/api/shipments_controller_spec.rb +16 -1
  130. data/spec/requests/spree/api/states_controller_spec.rb +1 -0
  131. data/spec/requests/spree/api/taxons_controller_spec.rb +25 -0
  132. data/spec/requests/spree/api/users_controller_spec.rb +1 -1
  133. data/spec/support/be_paginated_matcher.rb +7 -0
  134. data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +1 -0
  135. data/spec/test_views/spree/api/widgets/index.json.jbuilder +7 -0
  136. data/spec/test_views/spree/api/widgets/new.json.jbuilder +1 -0
  137. data/spec/test_views/spree/api/widgets/show.json.jbuilder +1 -0
  138. metadata +166 -111
  139. data/app/views/spree/api/address_books/show.v1.rabl +0 -7
  140. data/app/views/spree/api/addresses/show.v1.rabl +0 -10
  141. data/app/views/spree/api/adjustments/show.v1.rabl +0 -4
  142. data/app/views/spree/api/config/money.v1.rabl +0 -2
  143. data/app/views/spree/api/config/show.v1.rabl +0 -3
  144. data/app/views/spree/api/countries/index.v1.rabl +0 -7
  145. data/app/views/spree/api/countries/show.v1.rabl +0 -5
  146. data/app/views/spree/api/credit_cards/index.v1.rabl +0 -7
  147. data/app/views/spree/api/credit_cards/show.v1.rabl +0 -7
  148. data/app/views/spree/api/errors/gateway_error.v1.rabl +0 -2
  149. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +0 -2
  150. data/app/views/spree/api/errors/invalid_resource.v1.rabl +0 -3
  151. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +0 -2
  152. data/app/views/spree/api/errors/not_found.v1.rabl +0 -2
  153. data/app/views/spree/api/errors/unauthorized.v1.rabl +0 -2
  154. data/app/views/spree/api/errors/variant_not_in_stock_transfer.v1.rabl +0 -2
  155. data/app/views/spree/api/images/index.v1.rabl +0 -4
  156. data/app/views/spree/api/images/show.v1.rabl +0 -6
  157. data/app/views/spree/api/inventory_units/show.rabl +0 -2
  158. data/app/views/spree/api/line_items/new.v1.rabl +0 -3
  159. data/app/views/spree/api/line_items/show.v1.rabl +0 -15
  160. data/app/views/spree/api/option_types/index.v1.rabl +0 -3
  161. data/app/views/spree/api/option_types/show.v1.rabl +0 -5
  162. data/app/views/spree/api/option_values/index.v1.rabl +0 -3
  163. data/app/views/spree/api/option_values/show.v1.rabl +0 -2
  164. data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +0 -2
  165. data/app/views/spree/api/orders/could_not_transition.v1.rabl +0 -3
  166. data/app/views/spree/api/orders/expected_total_mismatch.v1.rabl +0 -2
  167. data/app/views/spree/api/orders/index.v1.rabl +0 -7
  168. data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +0 -2
  169. data/app/views/spree/api/orders/mine.v1.rabl +0 -9
  170. data/app/views/spree/api/orders/order.v1.rabl +0 -9
  171. data/app/views/spree/api/orders/show.v1.rabl +0 -53
  172. data/app/views/spree/api/payments/credit_over_limit.v1.rabl +0 -2
  173. data/app/views/spree/api/payments/index.v1.rabl +0 -7
  174. data/app/views/spree/api/payments/new.v1.rabl +0 -5
  175. data/app/views/spree/api/payments/show.v1.rabl +0 -2
  176. data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
  177. data/app/views/spree/api/product_properties/index.v1.rabl +0 -7
  178. data/app/views/spree/api/product_properties/new.v1.rabl +0 -2
  179. data/app/views/spree/api/product_properties/show.v1.rabl +0 -2
  180. data/app/views/spree/api/products/index.v1.rabl +0 -9
  181. data/app/views/spree/api/products/new.v1.rabl +0 -3
  182. data/app/views/spree/api/products/product.v1.rabl +0 -1
  183. data/app/views/spree/api/products/show.v1.rabl +0 -42
  184. data/app/views/spree/api/promotions/handler.v1.rabl +0 -5
  185. data/app/views/spree/api/promotions/show.v1.rabl +0 -2
  186. data/app/views/spree/api/properties/index.v1.rabl +0 -7
  187. data/app/views/spree/api/properties/new.v1.rabl +0 -2
  188. data/app/views/spree/api/properties/show.v1.rabl +0 -2
  189. data/app/views/spree/api/return_authorizations/index.v1.rabl +0 -7
  190. data/app/views/spree/api/return_authorizations/new.v1.rabl +0 -3
  191. data/app/views/spree/api/return_authorizations/show.v1.rabl +0 -2
  192. data/app/views/spree/api/shipments/big.v1.rabl +0 -55
  193. data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +0 -2
  194. data/app/views/spree/api/shipments/mine.v1.rabl +0 -9
  195. data/app/views/spree/api/shipments/show.v1.rabl +0 -32
  196. data/app/views/spree/api/shipments/small.v1.rabl +0 -37
  197. data/app/views/spree/api/shipping_rates/show.v1.rabl +0 -2
  198. data/app/views/spree/api/states/index.v1.rabl +0 -14
  199. data/app/views/spree/api/states/show.v1.rabl +0 -2
  200. data/app/views/spree/api/stock_items/index.v1.rabl +0 -7
  201. data/app/views/spree/api/stock_items/show.v1.rabl +0 -5
  202. data/app/views/spree/api/stock_locations/index.v1.rabl +0 -7
  203. data/app/views/spree/api/stock_locations/show.v1.rabl +0 -8
  204. data/app/views/spree/api/stock_movements/index.v1.rabl +0 -7
  205. data/app/views/spree/api/stock_movements/show.v1.rabl +0 -5
  206. data/app/views/spree/api/stock_transfers/receive.v1.rabl +0 -5
  207. data/app/views/spree/api/store_credit_events/mine.v1.rabl +0 -10
  208. data/app/views/spree/api/stores/index.v1.rabl +0 -4
  209. data/app/views/spree/api/stores/show.v1.rabl +0 -2
  210. data/app/views/spree/api/taxonomies/index.v1.rabl +0 -7
  211. data/app/views/spree/api/taxonomies/jstree.rabl +0 -8
  212. data/app/views/spree/api/taxonomies/nested.v1.rabl +0 -11
  213. data/app/views/spree/api/taxonomies/new.v1.rabl +0 -3
  214. data/app/views/spree/api/taxonomies/show.v1.rabl +0 -15
  215. data/app/views/spree/api/taxons/index.v1.rabl +0 -12
  216. data/app/views/spree/api/taxons/jstree.rabl +0 -8
  217. data/app/views/spree/api/taxons/new.v1.rabl +0 -3
  218. data/app/views/spree/api/taxons/show.v1.rabl +0 -6
  219. data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
  220. data/app/views/spree/api/transfer_items/show.v1.rabl +0 -6
  221. data/app/views/spree/api/users/index.v1.rabl +0 -7
  222. data/app/views/spree/api/users/new.v1.rabl +0 -3
  223. data/app/views/spree/api/users/show.v1.rabl +0 -10
  224. data/app/views/spree/api/variants/big.v1.rabl +0 -20
  225. data/app/views/spree/api/variants/index.v1.rabl +0 -9
  226. data/app/views/spree/api/variants/new.v1.rabl +0 -2
  227. data/app/views/spree/api/variants/show.v1.rabl +0 -3
  228. data/app/views/spree/api/variants/small.v1.rabl +0 -17
  229. data/app/views/spree/api/zones/index.v1.rabl +0 -7
  230. data/app/views/spree/api/zones/show.v1.rabl +0 -6
  231. data/config/initializers/rails5_rabl_hacks.rb +0 -12
  232. data/spec/test_views/spree/api/widgets/index.v1.rabl +0 -7
  233. data/spec/test_views/spree/api/widgets/new.v1.rabl +0 -2
  234. data/spec/test_views/spree/api/widgets/show.v1.rabl +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62e84e7fac19cf7c464a975f5ce5e32b445f6c0d
4
- data.tar.gz: 7058e689b5789d92b852345a668b7725a05cb26c
3
+ metadata.gz: 5be6f6cc794cc0b05b877514c744c20dd9c2526d
4
+ data.tar.gz: 85a853cdb5bc1c4f82f6db59680c9798ca4177b8
5
5
  SHA512:
6
- metadata.gz: '08ecdd913e61cf55169cd386e35046a1d977b4590470f57ba7710c7d50c0d1f606c163d7e7805985fb1351beae2a582587df71a674697e107037f228a2456d70'
7
- data.tar.gz: 22a48ebbaafc4f9c0eabfc4bc7227fe18e73e5db0fe56bacdcc5c9910fe5602d207086c19d0cf1721dfbd0a1ea9fe1df24eaa175b5054cfa8164367b2fb16d0c
6
+ metadata.gz: a323da1f10210b484fb2db8023fe737e1b50751e20898c8ac0f9ea0ce040f9867f9020107286c173a5bb2dcb894efe706e19f71418b4fcaf2f2ad154607e0da8
7
+ data.tar.gz: 77da8b610469e19eefffb780e9e237a33fa52734392fe72e5fa0c9f3ba8a54475ba26d61aedf4c3c35670f5016032b8db2492e8714e7f07c720da01b0379fc26
@@ -16,14 +16,12 @@ module Spree
16
16
 
17
17
  attr_accessor :current_api_user
18
18
 
19
- class_attribute :error_notifier
20
-
21
19
  before_action :load_user
22
20
  before_action :authorize_for_order, if: proc { order_token.present? }
23
21
  before_action :authenticate_user
24
22
  before_action :load_user_roles
25
23
 
26
- rescue_from StandardError, with: :error_during_processing
24
+ rescue_from ActionController::ParameterMissing, with: :parameter_missing_error
27
25
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
28
26
  rescue_from CanCan::AccessDenied, with: :unauthorized
29
27
  rescue_from Spree::Core::GatewayError, with: :gateway_error
@@ -67,20 +65,19 @@ module Spree
67
65
  render "spree/api/errors/unauthorized", status: 401
68
66
  end
69
67
 
70
- def error_during_processing(exception)
71
- Rails.logger.error exception.message
72
- Rails.logger.error exception.backtrace.join("\n")
73
-
74
- error_notifier.call(exception, self) if error_notifier
75
-
76
- render json: { exception: exception.message }, status: 422
77
- end
78
-
79
68
  def gateway_error(exception)
80
69
  @order.errors.add(:base, exception.message)
81
70
  invalid_resource!(@order)
82
71
  end
83
72
 
73
+ def parameter_missing_error(exception)
74
+ render json: {
75
+ exception: exception.message,
76
+ error: exception.message,
77
+ missing_param: exception.param
78
+ }, status: 422
79
+ end
80
+
84
81
  def requires_authentication?
85
82
  Spree::Api::Config[:requires_authentication]
86
83
  end
@@ -12,9 +12,6 @@ module Spree
12
12
  # TODO: Remove this after deprecated usage in #update is removed
13
13
  include Spree::Core::ControllerHelpers::PaymentParameters
14
14
 
15
- # This before_action comes from Spree::Core::ControllerHelpers::Order
16
- skip_before_action :set_current_order
17
-
18
15
  def next
19
16
  authorize! :update, @order, order_token
20
17
  if !expected_total_ok?(params[:expected_total])
@@ -115,11 +112,12 @@ module Spree
115
112
 
116
113
  def after_update_attributes
117
114
  if params[:order] && params[:order][:coupon_code].present?
118
- handler = PromotionHandler::Coupon.new(@order).apply
115
+ handler = PromotionHandler::Coupon.new(@order)
116
+ handler.apply
119
117
 
120
118
  if handler.error.present?
121
119
  @coupon_message = handler.error
122
- respond_with(@order, default_template: 'spree/api/orders/could_not_apply_coupon')
120
+ respond_with(@order, default_template: 'spree/api/orders/could_not_apply_coupon', status: 422)
123
121
  return true
124
122
  end
125
123
  end
@@ -27,18 +27,8 @@ module Spree
27
27
 
28
28
  def create
29
29
  authorize! :create, Order
30
-
31
- if can?(:admin, Order)
32
- @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
33
- respond_with(@order, default_template: :show, status: 201)
34
- else
35
- @order = Spree::Order.create!(user: current_api_user, store: current_store)
36
- if OrderUpdateAttributes.new(@order, order_params).apply
37
- respond_with(@order, default_template: :show, status: 201)
38
- else
39
- invalid_resource!(@order)
40
- end
41
- end
30
+ @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
31
+ respond_with(@order, default_template: :show, status: 201)
42
32
  end
43
33
 
44
34
  def empty
@@ -16,7 +16,6 @@ module Spree
16
16
  end
17
17
 
18
18
  def create
19
- @order.validate_payments_attributes(payment_params)
20
19
  @payment = PaymentCreate.new(@order, payment_params).build
21
20
  if @payment.save
22
21
  respond_with(@payment, status: 201, default_template: :show)
@@ -56,6 +56,8 @@ class Spree::Api::ResourceController < Spree::Api::BaseController
56
56
  else
57
57
  invalid_resource!(@object)
58
58
  end
59
+ rescue ActiveRecord::DeleteRestrictionError
60
+ render "spree/api/errors/delete_restriction", status: 422
59
61
  end
60
62
 
61
63
  protected
@@ -81,15 +81,26 @@ module Spree
81
81
  end
82
82
 
83
83
  def transfer_to_location
84
- @stock_location = Spree::StockLocation.find(params[:stock_location_id])
85
- @original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
86
- render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
84
+ @desired_stock_location = Spree::StockLocation.find(params[:stock_location_id])
85
+ @desired_shipment = @original_shipment.order.shipments.build(stock_location: @desired_stock_location)
86
+ transfer_to_shipment
87
87
  end
88
88
 
89
89
  def transfer_to_shipment
90
- @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
91
- @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
92
- render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
90
+ @desired_shipment ||= Spree::Shipment.find_by!(number: params[:target_shipment_number])
91
+
92
+ fulfilment_changer = Spree::FulfilmentChanger.new(
93
+ current_shipment: @original_shipment,
94
+ desired_shipment: @desired_shipment,
95
+ variant: @variant,
96
+ quantity: @quantity
97
+ )
98
+
99
+ if fulfilment_changer.run!
100
+ render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: :accepted
101
+ else
102
+ render json: { success: false, message: fulfilment_changer.errors.full_messages.to_sentence }, status: :accepted
103
+ end
93
104
  end
94
105
 
95
106
  private
@@ -3,6 +3,8 @@ module Spree
3
3
  class StockItemsController < Spree::Api::BaseController
4
4
  before_action :load_stock_location, only: [:index, :show, :create]
5
5
 
6
+ rescue_from StockLocation::InvalidMovementError, with: :render_stock_items_error
7
+
6
8
  def index
7
9
  @stock_items = paginate(scope.ransack(params[:q]).result)
8
10
  respond_with(@stock_items)
@@ -78,6 +80,10 @@ module Spree
78
80
  @stock_movement = @stock_location.move(@stock_item.variant, count_on_hand_adjustment, current_api_user)
79
81
  @stock_item = @stock_movement.stock_item
80
82
  end
83
+
84
+ def render_stock_items_error
85
+ render json: { error: Spree.t(:stock_not_below_zero) }, status: 422
86
+ end
81
87
  end
82
88
  end
83
89
  end
@@ -115,8 +115,7 @@ module Spree
115
115
  ]
116
116
 
117
117
  @@inventory_unit_attributes = [
118
- :id, :lock_version, :state, :variant_id, :shipment_id,
119
- :return_authorization_id
118
+ :id, :state, :variant_id, :shipment_id
120
119
  ]
121
120
 
122
121
  @@return_authorization_attributes = [
@@ -136,7 +135,7 @@ module Spree
136
135
  @@adjustment_attributes = [
137
136
  :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
138
137
  :amount, :label, :promotion_code,
139
- :locked, :eligible, :created_at, :updated_at
138
+ :finalized, :eligible, :created_at, :updated_at
140
139
  ]
141
140
 
142
141
  @@creditcard_attributes = [
@@ -159,7 +158,7 @@ module Spree
159
158
  @@stock_movement_attributes = [:id, :quantity, :stock_item_id]
160
159
 
161
160
  @@stock_item_attributes = [
162
- :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
161
+ :id, :count_on_hand, :backorderable, :stock_location_id,
163
162
  :variant_id
164
163
  ]
165
164
 
@@ -0,0 +1,4 @@
1
+ inherit_from: ../../../.rubocop.yml
2
+
3
+ Style/LambdaCall:
4
+ EnforcedStyle: braces
@@ -0,0 +1,11 @@
1
+ json.array! @user_addresses do |user_address|
2
+ json.partial!("spree/api/addresses/address", address: user_address.address)
3
+
4
+ json.default user_address.default
5
+
6
+ # This is a bit of a hack.
7
+ # This attribute is only shown on the update action
8
+ if @address
9
+ json.update_target @address == user_address.address
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ json.cache! address do
2
+ json.(address, *address_attributes)
3
+ json.country do
4
+ if address.country
5
+ json.(address.country, *country_attributes)
6
+ else
7
+ json.nil!
8
+ end
9
+ end
10
+ json.state do
11
+ if address.state
12
+ json.(address.state, *state_attributes)
13
+ else
14
+ json.nil!
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/addresses/address", address: @address)
@@ -0,0 +1,4 @@
1
+ json.cache! [I18n.locale, adjustment] do
2
+ json.(adjustment, *adjustment_attributes)
3
+ json.display_amount(adjustment.display_amount.to_s)
4
+ end
@@ -0,0 +1 @@
1
+ json.symbol(::Money.new(1, Spree::Config[:currency]).symbol)
@@ -0,0 +1,2 @@
1
+ json.default_country_id(Spree::Country.default.id)
2
+ json.default_country_iso(Spree::Config[:default_country_iso])
@@ -0,0 +1,2 @@
1
+ json.countries(@countries) { |country| json.(country, *country_attributes) }
2
+ json.partial! 'spree/api/shared/pagination', pagination: @countries
@@ -0,0 +1,4 @@
1
+ json.(@country, *country_attributes)
2
+ json.states(@country.states) do |state|
3
+ json.(state, :id, :name, :abbr, :country_id)
4
+ end
@@ -0,0 +1,10 @@
1
+ json.cache! [I18n.locale, credit_card] do
2
+ json.(credit_card, *creditcard_attributes)
3
+ json.address do
4
+ if credit_card.address
5
+ json.partial!("spree/api/addresses/address", address: credit_card.address)
6
+ else
7
+ json.nil!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ json.credit_cards(@credit_cards) do |credit_card|
2
+ json.partial!("spree/api/credit_cards/credit_card", credit_card: credit_card)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @credit_cards
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/credit_cards/credit_card", credit_card: @credit_card)
@@ -0,0 +1 @@
1
+ json.error I18n.t(:delete_restriction_error, scope: "spree.api")
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:gateway_error, scope: "spree.api", text: @error))
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:invalid_api_key, key: api_key, scope: "spree.api"))
@@ -0,0 +1,2 @@
1
+ json.error(I18n.t(:invalid_resource, scope: "spree.api"))
2
+ json.errors(@resource.errors.to_hash)
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:must_specify_api_key, scope: "spree.api"))
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:resource_not_found, scope: "spree.api"))
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:unauthorized, scope: "spree.api"))
@@ -0,0 +1 @@
1
+ json.error(Spree.t(:item_not_in_stock_transfer))
@@ -0,0 +1,5 @@
1
+ json.(image, *image_attributes)
2
+ json.(image, :viewable_type, :viewable_id)
3
+ Spree::Image.attachment_definitions[:attachment][:styles].each do |k, _v|
4
+ json.set! "#{k}_url", image.attachment.url(k)
5
+ end
@@ -0,0 +1,3 @@
1
+ json.images(@images) do |image|
2
+ json.partial!("spree/api/images/image", image: image)
3
+ end
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/images/image", image: @image)
@@ -0,0 +1 @@
1
+ json.(@inventory_unit, *inventory_unit_attributes)
@@ -0,0 +1,16 @@
1
+ json.cache! [I18n.locale, line_item] do
2
+ json.(line_item, *line_item_attributes)
3
+ json.single_display_amount(line_item.single_display_amount.to_s)
4
+ json.display_amount(line_item.display_amount.to_s)
5
+ json.total(line_item.total)
6
+ json.variant do
7
+ json.partial!("spree/api/variants/small", variant: line_item.variant)
8
+ json.(line_item.variant, :product_id)
9
+ json.images(line_item.variant.images) do |image|
10
+ json.partial!("spree/api/images/image", image: image)
11
+ end
12
+ end
13
+ json.adjustments(line_item.adjustments) do |adjustment|
14
+ json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ json.attributes(([*line_item_attributes] - [:id]))
2
+ json.required_attributes([:variant_id, :quantity])
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/line_items/line_item", line_item: @line_item)
@@ -0,0 +1,4 @@
1
+ json.(option_type, *option_type_attributes)
2
+ json.option_values(option_type.option_values) do |option_value|
3
+ json.(option_value, *option_value_attributes)
4
+ end
@@ -0,0 +1,3 @@
1
+ json.array! @option_types do |option_type|
2
+ json.partial!("spree/api/option_types/option_type", option_type: option_type)
3
+ end
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/option_types/option_type", option_type: @option_type)
@@ -0,0 +1 @@
1
+ json.(option_value, *option_value_attributes)
@@ -0,0 +1,3 @@
1
+ json.array! @option_values do |option_value|
2
+ json.partial!("spree/api/option_values/option_value", option_value: option_value)
3
+ end
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/option_values/option_value", option_value: @option_value)
@@ -0,0 +1,49 @@
1
+ json.partial!("spree/api/orders/order", order: order)
2
+ json.payment_methods(order.available_payment_methods) do |payment_method|
3
+ json.(payment_method, :id, :name, :partial_name)
4
+ json.method_type payment_method.partial_name
5
+ end
6
+ json.bill_address do
7
+ if order.billing_address
8
+ json.partial!("spree/api/addresses/address", address: order.billing_address)
9
+ else
10
+ json.nil!
11
+ end
12
+ end
13
+ json.ship_address do
14
+ if order.shipping_address
15
+ json.partial!("spree/api/addresses/address", address: order.shipping_address)
16
+ else
17
+ json.nil!
18
+ end
19
+ end
20
+ json.line_items(order.line_items) do |line_item|
21
+ json.partial!("spree/api/line_items/line_item", line_item: line_item)
22
+ end
23
+ json.payments(order.payments) do |payment|
24
+ json.(payment, *payment_attributes)
25
+ json.payment_method { json.(payment.payment_method, :id, :name) }
26
+ json.source do
27
+ if payment.source
28
+ json.(payment.source, *payment_source_attributes)
29
+
30
+ if @current_user_roles.include?("admin")
31
+ json.(payment.source, :gateway_customer_profile_id, :gateway_payment_profile_id)
32
+ end
33
+ else
34
+ json.nil!
35
+ end
36
+ end
37
+ end
38
+ json.shipments(order.shipments) do |shipment|
39
+ json.partial!("spree/api/shipments/small", shipment: shipment)
40
+ end
41
+ json.adjustments(order.adjustments) do |adjustment|
42
+ json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment)
43
+ end
44
+ json.permissions do
45
+ json.can_update current_ability.can?(:update, order)
46
+ end
47
+ json.credit_cards(order.valid_credit_cards) do |credit_card|
48
+ json.partial!("spree/api/credit_cards/credit_card", credit_card: credit_card)
49
+ end
@@ -0,0 +1,10 @@
1
+ json.cache! [I18n.locale, order] do
2
+ json.(order, *order_attributes)
3
+ json.display_item_total(order.display_item_total.to_s)
4
+ json.total_quantity(order.line_items.sum(:quantity))
5
+ json.display_total(order.display_total.to_s)
6
+ json.display_ship_total(order.display_ship_total)
7
+ json.display_tax_total(order.display_tax_total)
8
+ json.token(order.guest_token)
9
+ json.checkout_steps(order.checkout_steps)
10
+ end
@@ -0,0 +1 @@
1
+ json.error(@coupon_message)
@@ -0,0 +1,2 @@
1
+ json.error(I18n.t(:could_not_transition, scope: "spree.api.order"))
2
+ json.errors(@order.errors.to_hash)
@@ -0,0 +1 @@
1
+ json.errors(expected_total: [I18n.t(:expected_total_mismatch, scope: "spree.api.order")])
@@ -0,0 +1,4 @@
1
+ json.orders(@orders) do |order|
2
+ json.partial!("spree/api/orders/order", order: order)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @orders
@@ -0,0 +1 @@
1
+ json.errors([I18n.t(:invalid_shipping_method, scope: "spree.api.order")])
@@ -0,0 +1,4 @@
1
+ json.orders(@orders) do |order|
2
+ json.partial!("spree/api/orders/big", order: order)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @orders
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/orders/big", order: @order)
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:credit_over_limit, limit: @payment.credit_allowed, scope: "spree.api.payment"))
@@ -0,0 +1,2 @@
1
+ json.payments(@payments) { |payment| json.(payment, *payment_attributes) }
2
+ json.partial! 'spree/api/shared/pagination', pagination: @payments
@@ -0,0 +1,4 @@
1
+ json.attributes([*payment_attributes])
2
+ json.payment_methods(@payment_methods) do |payment_method|
3
+ json.(payment_method, *payment_method_attributes)
4
+ end
@@ -0,0 +1 @@
1
+ json.(@payment, *payment_attributes)
@@ -0,0 +1 @@
1
+ json.error(I18n.t(:update_forbidden, state: @payment.state, scope: "spree.api.payment"))
@@ -0,0 +1,4 @@
1
+ json.product_properties(@product_properties) do |product_property|
2
+ json.(product_property, *product_property_attributes)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @product_properties
@@ -0,0 +1,2 @@
1
+ json.attributes([*product_property_attributes])
2
+ json.required_attributes([])
@@ -0,0 +1 @@
1
+ json.(@product_property, *product_property_attributes)
@@ -0,0 +1,34 @@
1
+ @product_attributes ||= product_attributes
2
+ json.cache! [I18n.locale, @current_user_roles.include?('admin'), current_pricing_options, @product_attributes, @exclude_data, product] do
3
+ json.(product, *@product_attributes)
4
+ json.display_price(product.display_price.to_s)
5
+
6
+ @exclude_data ||= {}
7
+ unless @exclude_data[:variants]
8
+ json.has_variants(product.has_variants?)
9
+ json.master do
10
+ json.partial!("spree/api/variants/small", variant: product.master)
11
+ end
12
+ json.variants(product.variants) do |variant|
13
+ json.partial!("spree/api/variants/small", variant: variant)
14
+ end
15
+ end
16
+ unless @exclude_data[:option_types]
17
+ json.option_types(product.option_types) do |option_type|
18
+ json.(option_type, *option_type_attributes)
19
+ end
20
+ end
21
+ unless @exclude_data[:product_properties]
22
+ json.product_properties(product.product_properties) do |product_property|
23
+ json.(product_property, *product_property_attributes)
24
+ end
25
+ end
26
+ unless @exclude_data[:classifications]
27
+ json.classifications(product.classifications) do |classification|
28
+ json.(classification, :taxon_id, :position)
29
+ json.taxon do
30
+ json.partial!("spree/api/taxons/taxon", taxon: classification.taxon)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ json.partial! 'spree/api/shared/pagination', pagination: @products
2
+ json.products(@products) do |product|
3
+ json.partial!("spree/api/products/product", product: product)
4
+ end
@@ -0,0 +1,2 @@
1
+ json.attributes([*product_attributes])
2
+ json.required_attributes(required_fields_for(Spree::Product))
@@ -0,0 +1 @@
1
+ json.partial!("spree/api/products/product", product: @product)
@@ -0,0 +1,4 @@
1
+ json.success(@handler.success)
2
+ json.error(@handler.error)
3
+ json.successful(@handler.successful?)
4
+ json.status_code(@handler.status_code)
@@ -0,0 +1 @@
1
+ json.(@promotion, *promotion_attributes)
@@ -0,0 +1,4 @@
1
+ json.properties(@properties) do |property|
2
+ json.(property, *property_attributes)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @properties
@@ -0,0 +1,2 @@
1
+ json.attributes([*property_attributes])
2
+ json.required_attributes([])
@@ -0,0 +1 @@
1
+ json.(@property, *property_attributes)
@@ -0,0 +1,4 @@
1
+ json.return_authorizations(@return_authorizations) do |return_authorization|
2
+ json.(return_authorization, *return_authorization_attributes)
3
+ end
4
+ json.partial! 'spree/api/shared/pagination', pagination: @return_authorizations
@@ -0,0 +1,2 @@
1
+ json.attributes([*return_authorization_attributes])
2
+ json.required_attributes(required_fields_for(Spree::ReturnAuthorization))
@@ -0,0 +1 @@
1
+ json.(@return_authorization, *return_authorization_attributes)
@@ -0,0 +1,5 @@
1
+ json.count pagination.count
2
+ json.total_count pagination.total_count
3
+ json.current_page pagination.current_page
4
+ json.pages pagination.total_pages
5
+ json.per_page pagination.limit_value