solidus_api 1.2.3 → 1.3.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.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +3 -2
- data/app/controllers/spree/api/base_controller.rb +10 -15
- data/app/controllers/spree/api/checkouts_controller.rb +56 -55
- data/app/controllers/spree/api/classifications_controller.rb +4 -4
- data/app/controllers/spree/api/config_controller.rb +6 -1
- data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
- data/app/controllers/spree/api/images_controller.rb +13 -13
- data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
- data/app/controllers/spree/api/line_items_controller.rb +27 -23
- data/app/controllers/spree/api/option_types_controller.rb +6 -5
- data/app/controllers/spree/api/option_values_controller.rb +12 -12
- data/app/controllers/spree/api/orders_controller.rb +6 -17
- data/app/controllers/spree/api/payments_controller.rb +15 -17
- data/app/controllers/spree/api/product_properties_controller.rb +13 -14
- data/app/controllers/spree/api/products_controller.rb +31 -28
- data/app/controllers/spree/api/promotions_controller.rb +9 -8
- data/app/controllers/spree/api/properties_controller.rb +9 -10
- data/app/controllers/spree/api/resource_controller.rb +9 -1
- data/app/controllers/spree/api/shipments_controller.rb +18 -18
- data/app/controllers/spree/api/states_controller.rb +8 -7
- data/app/controllers/spree/api/stock_items_controller.rb +2 -1
- data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
- data/app/controllers/spree/api/stores_controller.rb +0 -1
- data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
- data/app/controllers/spree/api/taxons_controller.rb +20 -19
- data/app/controllers/spree/api/users_controller.rb +1 -4
- data/app/controllers/spree/api/variants_controller.rb +19 -18
- data/app/controllers/spree/api/zones_controller.rb +3 -4
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/api_configuration.rb +1 -1
- data/app/views/spree/api/config/show.v1.rabl +2 -1
- data/app/views/spree/api/products/show.v1.rabl +1 -1
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
- data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
- data/lib/spree/api/engine.rb +8 -8
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/caching.rb +4 -4
- data/script/rails +0 -1
- data/solidus_api.gemspec +3 -3
- data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
- data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
- data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
- data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
- data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
- data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
- data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
- data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
- data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
- data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
- data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
- data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
- data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
- data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
- data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
- data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
- data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
- data/spec/features/checkout_spec.rb +2 -2
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/api/address_books_spec.rb +10 -11
- data/spec/requests/rabl_cache_spec.rb +7 -7
- data/spec/requests/ransackable_attributes_spec.rb +5 -7
- data/spec/shared_examples/protect_product_actions.rb +3 -4
- data/spec/spec_helper.rb +8 -4
- data/spec/support/controller_hacks.rb +5 -5
- data/spec/support/have_attributes_matcher.rb +0 -4
- data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
- metadata +9 -10
- data/app/models/spree/option_value_decorator.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1660d14deff32b5456115f64d5eb3defa14e6f9e
|
4
|
+
data.tar.gz: a949a6bf3dceabc39885d44a83a7b3d4f9663e8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e54a0c3abaed5e939daf3e9b09506125701abaf78e99a06d523850e8c58a2565e7526021c0351a588583e765aace4310d4bbec044c52ac755e1bdf1b05fe5a7c
|
7
|
+
data.tar.gz: ce1839a1b058a1b42259c0951201390fbab247ad05e095e059dfe384ca1f79ce1a0940cad12cd06c8992cd0fd95be724352596c405729339d956c97bdc1c80ba
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -13,9 +13,9 @@ module Spree
|
|
13
13
|
authorize! :update, @order, order_token
|
14
14
|
find_address
|
15
15
|
|
16
|
-
if @order.update_attributes({"#{@order_source}_attributes" => address_params})
|
16
|
+
if @order.update_attributes({ "#{@order_source}_attributes" => address_params })
|
17
17
|
@address = @order.send(@order_source)
|
18
|
-
respond_with(@address, :
|
18
|
+
respond_with(@address, default_template: :show)
|
19
19
|
else
|
20
20
|
@address = @order.send(@order_source)
|
21
21
|
invalid_resource!(@address)
|
@@ -23,6 +23,7 @@ module Spree
|
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
|
+
|
26
27
|
def address_params
|
27
28
|
params.require(:address).permit(permitted_address_attributes)
|
28
29
|
end
|
@@ -8,6 +8,7 @@ module Spree
|
|
8
8
|
|
9
9
|
include CanCan::ControllerAdditions
|
10
10
|
include Spree::Core::ControllerHelpers::Store
|
11
|
+
include Spree::Core::ControllerHelpers::Pricing
|
11
12
|
include Spree::Core::ControllerHelpers::StrongParameters
|
12
13
|
|
13
14
|
class_attribute :admin_line_item_attributes
|
@@ -18,7 +19,7 @@ module Spree
|
|
18
19
|
class_attribute :error_notifier
|
19
20
|
|
20
21
|
before_action :load_user
|
21
|
-
before_action :authorize_for_order, if:
|
22
|
+
before_action :authorize_for_order, if: proc { order_token.present? }
|
22
23
|
before_action :authenticate_user
|
23
24
|
before_action :load_user_roles
|
24
25
|
|
@@ -47,9 +48,9 @@ module Spree
|
|
47
48
|
def authenticate_user
|
48
49
|
unless @current_api_user
|
49
50
|
if requires_authentication? && api_key.blank? && order_token.blank?
|
50
|
-
render "spree/api/errors/must_specify_api_key", :
|
51
|
+
render "spree/api/errors/must_specify_api_key", status: 401
|
51
52
|
elsif order_token.blank? && (requires_authentication? || api_key.present?)
|
52
|
-
render "spree/api/errors/invalid_api_key", :
|
53
|
+
render "spree/api/errors/invalid_api_key", status: 401
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -93,15 +94,10 @@ module Spree
|
|
93
94
|
Spree::Ability.new(current_api_user)
|
94
95
|
end
|
95
96
|
|
96
|
-
def current_currency
|
97
|
-
Spree::Config[:currency]
|
98
|
-
end
|
99
|
-
helper_method :current_currency
|
100
|
-
|
101
97
|
def invalid_resource!(resource)
|
102
98
|
Rails.logger.error "invalid_resouce_errors=#{resource.errors.full_messages}"
|
103
99
|
@resource = resource
|
104
|
-
render "spree/api/errors/invalid_resource", :
|
100
|
+
render "spree/api/errors/invalid_resource", status: 422
|
105
101
|
end
|
106
102
|
|
107
103
|
def api_key
|
@@ -127,7 +123,7 @@ module Spree
|
|
127
123
|
scope = scope.not_deleted
|
128
124
|
end
|
129
125
|
else
|
130
|
-
scope = Product.accessible_by(current_ability, :read).
|
126
|
+
scope = Product.accessible_by(current_ability, :read).available.includes(*product_includes)
|
131
127
|
end
|
132
128
|
|
133
129
|
scope
|
@@ -138,7 +134,7 @@ module Spree
|
|
138
134
|
end
|
139
135
|
|
140
136
|
def product_includes
|
141
|
-
[
|
137
|
+
[:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]
|
142
138
|
end
|
143
139
|
|
144
140
|
def order_id
|
@@ -160,13 +156,12 @@ module Spree
|
|
160
156
|
logger.error "insufficient_stock_error #{exception.inspect}"
|
161
157
|
render(
|
162
158
|
json: {
|
163
|
-
errors: [I18n.t(:quantity_is_not_available, :
|
164
|
-
type: 'insufficient_stock'
|
159
|
+
errors: [I18n.t(:quantity_is_not_available, scope: "spree.api.order")],
|
160
|
+
type: 'insufficient_stock'
|
165
161
|
},
|
166
|
-
status: 422
|
162
|
+
status: 422
|
167
163
|
)
|
168
164
|
end
|
169
|
-
|
170
165
|
end
|
171
166
|
end
|
172
167
|
end
|
@@ -76,78 +76,79 @@ module Spree
|
|
76
76
|
end
|
77
77
|
|
78
78
|
private
|
79
|
-
def user_id
|
80
|
-
params[:order][:user_id] if params[:order]
|
81
|
-
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
def user_id
|
81
|
+
params[:order][:user_id] if params[:order]
|
82
|
+
end
|
83
|
+
|
84
|
+
def update_params
|
85
|
+
if update_params = massaged_params[:order]
|
86
|
+
update_params.permit(permitted_checkout_attributes)
|
87
|
+
else
|
88
|
+
# We current allow update requests without any parameters in them.
|
89
|
+
{}
|
90
90
|
end
|
91
|
+
end
|
91
92
|
|
92
|
-
|
93
|
-
|
93
|
+
def massaged_params
|
94
|
+
massaged_params = params.deep_dup
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
if params[:payment_source].present?
|
97
|
+
ActiveSupport::Deprecation.warn("Passing payment_source is deprecated. Send source parameters inside payments_attributes[:source_attributes].", caller)
|
98
|
+
move_payment_source_into_payments_attributes(massaged_params)
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
if params[:order] && params[:order][:existing_card].present?
|
102
|
+
ActiveSupport::Deprecation.warn("Passing order[:existing_card] is deprecated. Send existing_card_id inside of payments_attributes[:source_attributes].", caller)
|
103
|
+
move_existing_card_into_payments_attributes(massaged_params)
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
+
set_payment_parameters_amount(massaged_params, @order)
|
106
107
|
|
107
|
-
|
108
|
-
|
108
|
+
massaged_params
|
109
|
+
end
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
# Should be overriden if you have areas of your checkout that don't match
|
112
|
+
# up to a step within checkout_steps, such as a registration step
|
113
|
+
def skip_state_validation?
|
114
|
+
false
|
115
|
+
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
def load_order
|
118
|
+
@order = Spree::Order.find_by!(number: params[:id])
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
def update_order_state
|
122
|
+
@order.state = params[:state] if params[:state]
|
123
|
+
state_callback(:before)
|
124
|
+
end
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
def state_callback(before_or_after = :before)
|
127
|
+
method_name = :"#{before_or_after}_#{@order.state}"
|
128
|
+
send(method_name) if respond_to?(method_name, true)
|
129
|
+
end
|
129
130
|
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
def after_update_attributes
|
132
|
+
if params[:order] && params[:order][:coupon_code].present?
|
133
|
+
handler = PromotionHandler::Coupon.new(@order).apply
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
135
|
+
if handler.error.present?
|
136
|
+
@coupon_message = handler.error
|
137
|
+
respond_with(@order, default_template: 'spree/api/orders/could_not_apply_coupon')
|
138
|
+
return true
|
139
139
|
end
|
140
|
-
false
|
141
140
|
end
|
141
|
+
false
|
142
|
+
end
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
def order_id
|
145
|
+
super || params[:id]
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
def expected_total_ok?(expected_total)
|
149
|
+
return true if expected_total.blank?
|
150
|
+
@order.total == BigDecimal(expected_total)
|
151
|
+
end
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
@@ -5,14 +5,14 @@ module Spree
|
|
5
5
|
authorize! :update, Product
|
6
6
|
authorize! :update, Taxon
|
7
7
|
classification = Spree::Classification.find_by(
|
8
|
-
:
|
9
|
-
:
|
8
|
+
product_id: params[:product_id],
|
9
|
+
taxon_id: params[:taxon_id]
|
10
10
|
)
|
11
11
|
# Because position we get back is 0-indexed.
|
12
12
|
# acts_as_list is 1-indexed.
|
13
13
|
classification.insert_at(params[:position].to_i + 1)
|
14
|
-
render :
|
14
|
+
render nothing: true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -23,20 +23,20 @@ module Spree
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def user
|
27
|
+
if params[:user_id].present?
|
28
|
+
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:user_id])
|
30
29
|
end
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def find_credit_card
|
33
|
+
@credit_card = Spree::CreditCard.find(params[:id])
|
34
|
+
authorize! :update, @credit_card
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def credit_card_update_params
|
38
|
+
params.require(:credit_card).permit(permitted_credit_card_update_attributes)
|
39
|
+
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class ImagesController < Spree::Api::BaseController
|
4
|
-
|
5
4
|
def index
|
6
5
|
@images = scope.images.accessible_by(current_ability, :read)
|
7
6
|
respond_with(@images)
|
@@ -15,33 +14,34 @@ module Spree
|
|
15
14
|
def create
|
16
15
|
authorize! :create, Image
|
17
16
|
@image = scope.images.create(image_params)
|
18
|
-
respond_with(@image, :
|
17
|
+
respond_with(@image, status: 201, default_template: :show)
|
19
18
|
end
|
20
19
|
|
21
20
|
def update
|
22
21
|
@image = scope.images.accessible_by(current_ability, :update).find(params[:id])
|
23
22
|
@image.update_attributes(image_params)
|
24
|
-
respond_with(@image, :
|
23
|
+
respond_with(@image, default_template: :show)
|
25
24
|
end
|
26
25
|
|
27
26
|
def destroy
|
28
27
|
@image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
|
29
28
|
@image.destroy
|
30
|
-
respond_with(@image, :
|
29
|
+
respond_with(@image, status: 204)
|
31
30
|
end
|
32
31
|
|
33
32
|
private
|
34
|
-
def image_params
|
35
|
-
params.require(:image).permit(permitted_image_attributes)
|
36
|
-
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
def image_params
|
35
|
+
params.require(:image).permit(permitted_image_attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def scope
|
39
|
+
if params[:product_id]
|
40
|
+
Spree::Product.friendly.find(params[:product_id])
|
41
|
+
elsif params[:variant_id]
|
42
|
+
Spree::Variant.find(params[:variant_id])
|
44
43
|
end
|
44
|
+
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -14,7 +14,7 @@ module Spree
|
|
14
14
|
inventory_unit.transaction do
|
15
15
|
if inventory_unit.update_attributes(inventory_unit_params)
|
16
16
|
fire
|
17
|
-
render :show, :
|
17
|
+
render :show, status: 200
|
18
18
|
else
|
19
19
|
invalid_resource!(inventory_unit)
|
20
20
|
end
|
@@ -34,8 +34,8 @@ module Spree
|
|
34
34
|
|
35
35
|
unless inventory_unit.respond_to?(can_event) &&
|
36
36
|
inventory_unit.send(can_event)
|
37
|
-
render :
|
38
|
-
:
|
37
|
+
render text: { exception: "cannot transition to #{@event}" }.to_json,
|
38
|
+
status: 200
|
39
39
|
false
|
40
40
|
end
|
41
41
|
end
|
@@ -43,7 +43,7 @@ module Spree
|
|
43
43
|
def fire
|
44
44
|
inventory_unit.send("#{@event}!") if @event
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def inventory_unit_params
|
48
48
|
params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)
|
49
49
|
end
|
@@ -8,6 +8,9 @@ module Spree
|
|
8
8
|
before_filter :load_order, only: [:create, :update, :destroy]
|
9
9
|
around_filter :lock_order, only: [:create, :update, :destroy]
|
10
10
|
|
11
|
+
def new
|
12
|
+
end
|
13
|
+
|
11
14
|
def create
|
12
15
|
variant = Spree::Variant.find(params[:line_item][:variant_id])
|
13
16
|
@line_item = @order.contents.add(
|
@@ -42,32 +45,33 @@ module Spree
|
|
42
45
|
end
|
43
46
|
|
44
47
|
private
|
45
|
-
def load_order
|
46
|
-
@order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
|
47
|
-
authorize! :update, @order, order_token
|
48
|
-
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
def load_order
|
50
|
+
@order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
|
51
|
+
authorize! :update, @order, order_token
|
52
|
+
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}}
|
62
|
-
end
|
54
|
+
def find_line_item
|
55
|
+
id = params[:id].to_i
|
56
|
+
@order.line_items.detect { |line_item| line_item.id == id } ||
|
57
|
+
raise(ActiveRecord::RecordNotFound)
|
58
|
+
end
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
60
|
+
def line_items_attributes
|
61
|
+
{ line_items_attributes: {
|
62
|
+
id: params[:id],
|
63
|
+
quantity: params[:line_item][:quantity],
|
64
|
+
options: line_item_params[:options] || {}
|
65
|
+
} }
|
66
|
+
end
|
67
|
+
|
68
|
+
def line_item_params
|
69
|
+
params.require(:line_item).permit(
|
70
|
+
:quantity,
|
71
|
+
:variant_id,
|
72
|
+
options: line_item_options
|
73
|
+
)
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
authorize! :create, Spree::OptionType
|
20
20
|
@option_type = Spree::OptionType.new(option_type_params)
|
21
21
|
if @option_type.save
|
22
|
-
render :show, :
|
22
|
+
render :show, status: 201
|
23
23
|
else
|
24
24
|
invalid_resource!(@option_type)
|
25
25
|
end
|
@@ -37,13 +37,14 @@ module Spree
|
|
37
37
|
def destroy
|
38
38
|
@option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
|
39
39
|
@option_type.destroy
|
40
|
-
render :
|
40
|
+
render text: nil, status: 204
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
|
45
|
+
def option_type_params
|
46
|
+
params.require(:option_type).permit(permitted_option_type_attributes)
|
47
|
+
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
@@ -3,7 +3,7 @@ module Spree
|
|
3
3
|
class OptionValuesController < Spree::Api::BaseController
|
4
4
|
def index
|
5
5
|
if params[:ids]
|
6
|
-
@option_values = scope.where(:
|
6
|
+
@option_values = scope.where(id: params[:ids])
|
7
7
|
else
|
8
8
|
@option_values = scope.ransack(params[:q]).result.distinct
|
9
9
|
end
|
@@ -19,7 +19,7 @@ module Spree
|
|
19
19
|
authorize! :create, Spree::OptionValue
|
20
20
|
@option_value = scope.new(option_value_params)
|
21
21
|
if @option_value.save
|
22
|
-
render :show, :
|
22
|
+
render :show, status: 201
|
23
23
|
else
|
24
24
|
invalid_resource!(@option_value)
|
25
25
|
end
|
@@ -37,22 +37,22 @@ module Spree
|
|
37
37
|
def destroy
|
38
38
|
@option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
39
39
|
@option_value.destroy
|
40
|
-
render :
|
40
|
+
render text: nil, status: 204
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
45
|
+
def scope
|
46
|
+
if params[:option_type_id]
|
47
|
+
@scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read)
|
48
|
+
else
|
49
|
+
@scope ||= Spree::OptionValue.accessible_by(current_ability, :read).load
|
51
50
|
end
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def option_value_params
|
54
|
+
params.require(:option_value).permit(permitted_option_value_attributes)
|
55
|
+
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
class OrdersController < Spree::Api::BaseController
|
4
4
|
class_attribute :admin_shipment_attributes
|
5
|
-
self.admin_shipment_attributes = [:shipping_method, :stock_location, :
|
5
|
+
self.admin_shipment_attributes = [:shipping_method, :stock_location, inventory_units: [:variant_id, :sku]]
|
6
6
|
|
7
7
|
class_attribute :admin_order_attributes
|
8
8
|
self.admin_order_attributes = [:import, :number, :completed_at, :locked_at, :channel, :user_id, :created_at]
|
@@ -21,25 +21,14 @@ module Spree
|
|
21
21
|
|
22
22
|
def cancel
|
23
23
|
authorize! :update, @order, params[:token]
|
24
|
-
@order.
|
25
|
-
respond_with(@order, :
|
24
|
+
@order.canceled_by(current_api_user)
|
25
|
+
respond_with(@order, default_template: :show)
|
26
26
|
end
|
27
27
|
|
28
28
|
def create
|
29
29
|
authorize! :create, Order
|
30
|
-
|
31
|
-
|
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
|
-
@order.update!
|
38
|
-
respond_with(@order, default_template: :show, status: 201)
|
39
|
-
else
|
40
|
-
invalid_resource!(@order)
|
41
|
-
end
|
42
|
-
end
|
30
|
+
@order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
|
31
|
+
respond_with(@order, default_template: :show, status: 201)
|
43
32
|
end
|
44
33
|
|
45
34
|
def empty
|
@@ -141,7 +130,7 @@ module Spree
|
|
141
130
|
end
|
142
131
|
end
|
143
132
|
|
144
|
-
def find_order(
|
133
|
+
def find_order(_lock = false)
|
145
134
|
@order = Spree::Order.find_by!(number: params[:id])
|
146
135
|
end
|
147
136
|
|