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.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +21 -22
  3. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  4. data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
  5. data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
  6. data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
  7. data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
  8. data/app/controllers/spree/api/v1/images_controller.rb +56 -0
  9. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  10. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  11. data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
  12. data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
  13. data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
  14. data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
  15. data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
  16. data/app/controllers/spree/api/v1/products_controller.rb +126 -0
  17. data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
  18. data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
  19. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
  20. data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
  21. data/app/controllers/spree/api/v1/states_controller.rb +37 -0
  22. data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
  23. data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
  24. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  25. data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
  26. data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
  27. data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
  28. data/app/controllers/spree/api/v1/users_controller.rb +60 -0
  29. data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
  30. data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
  31. data/app/helpers/spree/api/api_helpers.rb +3 -2
  32. data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
  33. data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
  34. data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
  35. data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
  36. data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
  37. data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
  38. data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
  39. data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
  40. data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
  41. data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
  42. data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
  43. data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
  44. data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
  45. data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
  46. data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
  47. data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
  48. data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
  49. data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
  50. data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
  51. data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
  52. data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
  53. data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
  54. data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
  55. data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
  56. data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
  57. data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
  58. data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
  59. data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
  60. data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
  61. data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
  62. data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
  63. data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
  64. data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
  65. data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
  66. data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
  67. data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
  68. data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
  69. data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
  70. data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
  71. data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
  72. data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
  73. data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
  74. data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
  75. data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
  76. data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
  77. data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
  78. data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
  79. data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
  80. data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
  81. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
  82. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
  83. data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
  84. data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
  85. data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
  86. data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
  87. data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
  88. data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
  89. data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
  90. data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
  91. data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
  92. data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
  93. data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
  94. data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
  95. data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
  96. data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
  97. data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
  98. data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
  99. data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
  100. data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
  101. data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
  102. data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
  103. data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
  104. data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
  105. data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
  106. data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
  107. data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
  108. data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
  109. data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
  110. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
  111. data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
  112. data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
  113. data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
  114. data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
  115. data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
  116. data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
  117. data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
  118. data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
  119. data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
  120. data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
  121. data/config/routes.rb +85 -88
  122. data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
  123. data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
  124. data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
  125. data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
  126. data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
  127. data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
  128. data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
  129. data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
  130. data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
  131. data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
  132. data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
  133. data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
  134. data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
  135. data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
  136. data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
  137. data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
  138. data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
  139. data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
  140. data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
  141. data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
  142. data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
  143. data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
  144. data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
  145. data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
  146. data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
  147. data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
  148. data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
  149. data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
  150. data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
  151. data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
  152. data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
  153. data/spec/requests/rabl_cache_spec.rb +2 -2
  154. data/spec/requests/ransackable_attributes_spec.rb +6 -6
  155. data/spec/requests/version_spec.rb +19 -0
  156. data/spree_api.gemspec +1 -1
  157. metadata +188 -185
  158. data/CHANGELOG.md +0 -3
  159. data/app/controllers/spree/api/addresses_controller.rb +0 -43
  160. data/app/controllers/spree/api/checkouts_controller.rb +0 -98
  161. data/app/controllers/spree/api/classifications_controller.rb +0 -18
  162. data/app/controllers/spree/api/countries_controller.rb +0 -23
  163. data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
  164. data/app/controllers/spree/api/images_controller.rb +0 -47
  165. data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
  166. data/app/controllers/spree/api/line_items_controller.rb +0 -69
  167. data/app/controllers/spree/api/option_types_controller.rb +0 -49
  168. data/app/controllers/spree/api/option_values_controller.rb +0 -58
  169. data/app/controllers/spree/api/orders_controller.rb +0 -130
  170. data/app/controllers/spree/api/payments_controller.rb +0 -80
  171. data/app/controllers/spree/api/product_properties_controller.rb +0 -72
  172. data/app/controllers/spree/api/products_controller.rb +0 -124
  173. data/app/controllers/spree/api/promotions_controller.rb +0 -26
  174. data/app/controllers/spree/api/properties_controller.rb +0 -70
  175. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
  176. data/app/controllers/spree/api/shipments_controller.rb +0 -149
  177. data/app/controllers/spree/api/states_controller.rb +0 -38
  178. data/app/controllers/spree/api/stock_items_controller.rb +0 -75
  179. data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
  180. data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
  181. data/app/controllers/spree/api/stores_controller.rb +0 -55
  182. data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
  183. data/app/controllers/spree/api/taxons_controller.rb +0 -93
  184. data/app/controllers/spree/api/users_controller.rb +0 -56
  185. data/app/controllers/spree/api/variants_controller.rb +0 -73
  186. data/app/controllers/spree/api/zones_controller.rb +0 -49
  187. data/app/models/spree/option_value_decorator.rb +0 -9
  188. data/app/views/spree/api/option_types/index.v1.rabl +0 -3
  189. data/app/views/spree/api/option_values/index.v1.rabl +0 -3
  190. data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
@@ -1,130 +0,0 @@
1
- module Spree
2
- module Api
3
- class OrdersController < Spree::Api::BaseController
4
- skip_before_action :check_for_user_or_api_key, only: :apply_coupon_code
5
- skip_before_action :authenticate_user, only: :apply_coupon_code
6
-
7
- before_action :find_order, except: [:create, :mine, :current, :index, :update]
8
-
9
- # Dynamically defines our stores checkout steps to ensure we check authorization on each step.
10
- Spree::Order.checkout_steps.keys.each do |step|
11
- define_method step do
12
- find_order
13
- authorize! :update, @order, params[:token]
14
- end
15
- end
16
-
17
- def cancel
18
- authorize! :update, @order, params[:token]
19
- @order.cancel!
20
- respond_with(@order, :default_template => :show)
21
- end
22
-
23
- def create
24
- authorize! :create, Spree::Order
25
- order_user = if @current_user_roles.include?('admin') && order_params[:user_id]
26
- Spree.user_class.find(order_params[:user_id])
27
- else
28
- current_api_user
29
- end
30
-
31
- import_params = if @current_user_roles.include?("admin")
32
- params[:order].present? ? params[:order].permit! : {}
33
- else
34
- order_params
35
- end
36
-
37
- @order = Spree::Core::Importer::Order.import(order_user, import_params)
38
- respond_with(@order, default_template: :show, status: 201)
39
- end
40
-
41
- def empty
42
- authorize! :update, @order, order_token
43
- @order.empty!
44
- render text: nil, status: 204
45
- end
46
-
47
- def index
48
- authorize! :index, Order
49
- @orders = Spree::Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
50
- respond_with(@orders)
51
- end
52
-
53
- def show
54
- authorize! :show, @order, order_token
55
- respond_with(@order)
56
- end
57
-
58
- def update
59
- find_order(true)
60
- authorize! :update, @order, order_token
61
-
62
- if @order.contents.update_cart(order_params)
63
- user_id = params[:order][:user_id]
64
- if current_api_user.has_spree_role?('admin') && user_id
65
- @order.associate_user!(Spree.user_class.find(user_id))
66
- end
67
- respond_with(@order, default_template: :show)
68
- else
69
- invalid_resource!(@order)
70
- end
71
- end
72
-
73
- def current
74
- @order = find_current_order
75
- if @order
76
- respond_with(@order, default_template: :show, locals: { root_object: @order })
77
- else
78
- head :no_content
79
- end
80
- end
81
-
82
- def mine
83
- if current_api_user.persisted?
84
- @orders = current_api_user.orders.reverse_chronological.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
85
- else
86
- render "spree/api/errors/unauthorized", status: :unauthorized
87
- end
88
- end
89
-
90
- def apply_coupon_code
91
- find_order
92
- authorize! :update, @order, order_token
93
- @order.coupon_code = params[:coupon_code]
94
- @handler = Spree::PromotionHandler::Coupon.new(@order).apply
95
- status = @handler.successful? ? 200 : 422
96
- render "spree/api/promotions/handler", :status => status
97
- end
98
-
99
- private
100
- def order_params
101
- if params[:order]
102
- normalize_params
103
- params.require(:order).permit(permitted_order_attributes)
104
- else
105
- {}
106
- end
107
- end
108
-
109
- def normalize_params
110
- params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]
111
- params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
112
- params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
113
- params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address]
114
- params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address]
115
- end
116
-
117
- def find_order(lock = false)
118
- @order = Spree::Order.lock(lock).friendly.find(params[:id])
119
- end
120
-
121
- def find_current_order
122
- current_api_user ? current_api_user.orders.incomplete.order(:created_at).last : nil
123
- end
124
-
125
- def order_id
126
- super || params[:id]
127
- end
128
- end
129
- end
130
- end
@@ -1,80 +0,0 @@
1
- module Spree
2
- module Api
3
- class PaymentsController < Spree::Api::BaseController
4
-
5
- before_action :find_order
6
- before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void]
7
-
8
- def index
9
- @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
- respond_with(@payments)
11
- end
12
-
13
- def new
14
- @payment_methods = Spree::PaymentMethod.available
15
- respond_with(@payment_methods)
16
- end
17
-
18
- def create
19
- @payment = @order.payments.build(payment_params)
20
- if @payment.save
21
- respond_with(@payment, status: 201, default_template: :show)
22
- else
23
- invalid_resource!(@payment)
24
- end
25
- end
26
-
27
- def update
28
- authorize! params[:action], @payment
29
- if !@payment.editable?
30
- render 'update_forbidden', status: 403
31
- elsif @payment.update_attributes(payment_params)
32
- respond_with(@payment, default_template: :show)
33
- else
34
- invalid_resource!(@payment)
35
- end
36
- end
37
-
38
- def show
39
- respond_with(@payment)
40
- end
41
-
42
- def authorize
43
- perform_payment_action(:authorize)
44
- end
45
-
46
- def capture
47
- perform_payment_action(:capture)
48
- end
49
-
50
- def purchase
51
- perform_payment_action(:purchase)
52
- end
53
-
54
- def void
55
- perform_payment_action(:void_transaction)
56
- end
57
-
58
- private
59
-
60
- def find_order
61
- @order = Spree::Order.friendly.find(order_id)
62
- authorize! :read, @order, order_token
63
- end
64
-
65
- def find_payment
66
- @payment = @order.payments.friendly.find(params[:id])
67
- end
68
-
69
- def perform_payment_action(action, *args)
70
- authorize! action, Spree::Payment
71
- @payment.send("#{action}!", *args)
72
- respond_with(@payment, default_template: :show)
73
- end
74
-
75
- def payment_params
76
- params.require(:payment).permit(permitted_payment_attributes)
77
- end
78
- end
79
- end
80
- end
@@ -1,72 +0,0 @@
1
- module Spree
2
- module Api
3
- class ProductPropertiesController < Spree::Api::BaseController
4
-
5
- before_action :find_product
6
- before_action :product_property, only: [:show, :update, :destroy]
7
-
8
- def index
9
- @product_properties = @product.product_properties.accessible_by(current_ability, :read).
10
- ransack(params[:q]).result.
11
- page(params[:page]).per(params[:per_page])
12
- respond_with(@product_properties)
13
- end
14
-
15
- def show
16
- respond_with(@product_property)
17
- end
18
-
19
- def new
20
- end
21
-
22
- def create
23
- authorize! :create, Spree::ProductProperty
24
- @product_property = @product.product_properties.new(product_property_params)
25
- if @product_property.save
26
- respond_with(@product_property, status: 201, default_template: :show)
27
- else
28
- invalid_resource!(@product_property)
29
- end
30
- end
31
-
32
- def update
33
- if @product_property
34
- authorize! :update, @product_property
35
- @product_property.update_attributes(product_property_params)
36
- respond_with(@product_property, status: 200, default_template: :show)
37
- else
38
- invalid_resource!(@product_property)
39
- end
40
- end
41
-
42
- def destroy
43
- if @product_property
44
- authorize! :destroy, @product_property
45
- @product_property.destroy
46
- respond_with(@product_property, status: 204)
47
- else
48
- invalid_resource!(@product_property)
49
- end
50
- end
51
-
52
- private
53
-
54
- def find_product
55
- @product = super(params[:product_id])
56
- authorize! :read, @product
57
- end
58
-
59
- def product_property
60
- if @product
61
- @product_property ||= @product.product_properties.find_by(id: params[:id])
62
- @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first
63
- authorize! :read, @product_property
64
- end
65
- end
66
-
67
- def product_property_params
68
- params.require(:product_property).permit(permitted_product_properties_attributes)
69
- end
70
- end
71
- end
72
- end
@@ -1,124 +0,0 @@
1
- module Spree
2
- module Api
3
- class ProductsController < Spree::Api::BaseController
4
-
5
- def index
6
- if params[:ids]
7
- @products = product_scope.where(id: params[:ids].split(",").flatten)
8
- else
9
- @products = product_scope.ransack(params[:q]).result
10
- end
11
-
12
- @products = @products.distinct.page(params[:page]).per(params[:per_page])
13
- expires_in 15.minutes, :public => true
14
- headers['Surrogate-Control'] = "max-age=#{15.minutes}"
15
- respond_with(@products)
16
- end
17
-
18
- def show
19
- @product = find_product(params[:id])
20
- expires_in 15.minutes, :public => true
21
- headers['Surrogate-Control'] = "max-age=#{15.minutes}"
22
- headers['Surrogate-Key'] = "product_id=1"
23
- respond_with(@product)
24
- end
25
-
26
- # Takes besides the products attributes either an array of variants or
27
- # an array of option types.
28
- #
29
- # By submitting an array of variants the option types will be created
30
- # using the *name* key in options hash. e.g
31
- #
32
- # product: {
33
- # ...
34
- # variants: {
35
- # price: 19.99,
36
- # sku: "hey_you",
37
- # options: [
38
- # { name: "size", value: "small" },
39
- # { name: "color", value: "black" }
40
- # ]
41
- # }
42
- # }
43
- #
44
- # Or just pass in the option types hash:
45
- #
46
- # product: {
47
- # ...
48
- # option_types: ['size', 'color']
49
- # }
50
- #
51
- # By passing the shipping category name you can fetch or create that
52
- # shipping category on the fly. e.g.
53
- #
54
- # product: {
55
- # ...
56
- # shipping_category: "Free Shipping Items"
57
- # }
58
- #
59
- def create
60
- authorize! :create, Spree::Product
61
- params[:product][:available_on] ||= Time.now
62
- set_up_shipping_category
63
-
64
- options = { variants_attrs: variants_params, options_attrs: option_types_params }
65
- @product = Spree::Core::Importer::Product.new(nil, product_params, options).create
66
-
67
- if @product.persisted?
68
- respond_with(@product, :status => 201, :default_template => :show)
69
- else
70
- invalid_resource!(@product)
71
- end
72
- end
73
-
74
- def update
75
- @product = find_product(params[:id])
76
- authorize! :update, @product
77
-
78
- options = { variants_attrs: variants_params, options_attrs: option_types_params }
79
- @product = Spree::Core::Importer::Product.new(@product, product_params, options).update
80
-
81
- if @product.errors.empty?
82
- respond_with(@product.reload, :status => 200, :default_template => :show)
83
- else
84
- invalid_resource!(@product)
85
- end
86
- end
87
-
88
- def destroy
89
- @product = find_product(params[:id])
90
- authorize! :destroy, @product
91
- @product.destroy
92
- respond_with(@product, :status => 204)
93
- end
94
-
95
- private
96
- def product_params
97
- params.require(:product).permit(permitted_product_attributes)
98
- end
99
-
100
- def variants_params
101
- variants_key = if params[:product].has_key? :variants
102
- :variants
103
- else
104
- :variants_attributes
105
- end
106
-
107
- params.require(:product).permit(
108
- variants_key => [permitted_variant_attributes, :id],
109
- ).delete(variants_key) || []
110
- end
111
-
112
- def option_types_params
113
- params[:product].fetch(:option_types, [])
114
- end
115
-
116
- def set_up_shipping_category
117
- if shipping_category = params[:product].delete(:shipping_category)
118
- id = Spree::ShippingCategory.find_or_create_by(name: shipping_category).id
119
- params[:product][:shipping_category_id] = id
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,26 +0,0 @@
1
- module Spree
2
- module Api
3
- class PromotionsController < Spree::Api::BaseController
4
- before_action :requires_admin
5
- before_action :load_promotion
6
-
7
- def show
8
- if @promotion
9
- respond_with(@promotion, default_template: :show)
10
- else
11
- raise ActiveRecord::RecordNotFound
12
- end
13
- end
14
-
15
- private
16
- def requires_admin
17
- return if @current_user_roles.include?("admin")
18
- unauthorized and return
19
- end
20
-
21
- def load_promotion
22
- @promotion = Spree::Promotion.find_by_id(params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
23
- end
24
- end
25
- end
26
- end
@@ -1,70 +0,0 @@
1
- module Spree
2
- module Api
3
- class PropertiesController < Spree::Api::BaseController
4
-
5
- before_action :find_property, only: [:show, :update, :destroy]
6
-
7
- def index
8
- @properties = Spree::Property.accessible_by(current_ability, :read)
9
-
10
- if params[:ids]
11
- @properties = @properties.where(id: params[:ids].split(",").flatten)
12
- else
13
- @properties = @properties.ransack(params[:q]).result
14
- end
15
-
16
- @properties = @properties.page(params[:page]).per(params[:per_page])
17
- respond_with(@properties)
18
- end
19
-
20
- def show
21
- respond_with(@property)
22
- end
23
-
24
- def new
25
- end
26
-
27
- def create
28
- authorize! :create, Spree::Property
29
- @property = Spree::Property.new(property_params)
30
- if @property.save
31
- respond_with(@property, status: 201, default_template: :show)
32
- else
33
- invalid_resource!(@property)
34
- end
35
- end
36
-
37
- def update
38
- if @property
39
- authorize! :update, @property
40
- @property.update_attributes(property_params)
41
- respond_with(@property, status: 200, default_template: :show)
42
- else
43
- invalid_resource!(@property)
44
- end
45
- end
46
-
47
- def destroy
48
- if @property
49
- authorize! :destroy, @property
50
- @property.destroy
51
- respond_with(@property, status: 204)
52
- else
53
- invalid_resource!(@property)
54
- end
55
- end
56
-
57
- private
58
-
59
- def find_property
60
- @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
61
- rescue ActiveRecord::RecordNotFound
62
- @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
63
- end
64
-
65
- def property_params
66
- params.require(:property).permit(permitted_property_attributes)
67
- end
68
- end
69
- end
70
- end