solidus_api 4.6.2 → 4.7.1
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.
- checksums.yaml +4 -4
- data/Rakefile +8 -8
- data/app/controllers/spree/api/addresses_controller.rb +4 -3
- data/app/controllers/spree/api/base_controller.rb +9 -9
- data/app/controllers/spree/api/checkouts_controller.rb +6 -6
- data/app/controllers/spree/api/countries_controller.rb +5 -5
- data/app/controllers/spree/api/coupon_codes_controller.rb +4 -4
- data/app/controllers/spree/api/customer_returns_controller.rb +11 -11
- data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
- data/app/controllers/spree/api/line_items_controller.rb +7 -7
- data/app/controllers/spree/api/option_types_controller.rb +3 -3
- data/app/controllers/spree/api/option_values_controller.rb +6 -6
- data/app/controllers/spree/api/orders_controller.rb +42 -12
- data/app/controllers/spree/api/payments_controller.rb +12 -1
- data/app/controllers/spree/api/product_properties_controller.rb +6 -6
- data/app/controllers/spree/api/products_controller.rb +11 -11
- data/app/controllers/spree/api/return_authorizations_controller.rb +5 -5
- data/app/controllers/spree/api/shipments_controller.rb +11 -11
- data/app/controllers/spree/api/states_controller.rb +2 -2
- data/app/controllers/spree/api/stock_items_controller.rb +3 -3
- data/app/controllers/spree/api/stock_locations_controller.rb +5 -5
- data/app/controllers/spree/api/taxonomies_controller.rb +9 -9
- data/app/controllers/spree/api/taxons_controller.rb +6 -6
- data/app/controllers/spree/api/variants_controller.rb +4 -4
- data/app/controllers/spree/api/zones_controller.rb +5 -5
- data/app/views/spree/api/addresses/_address.json.jbuilder +3 -3
- data/app/views/spree/api/adjustments/_adjustment.json.jbuilder +1 -1
- data/app/views/spree/api/countries/index.json.jbuilder +2 -2
- data/app/views/spree/api/countries/show.json.jbuilder +2 -2
- data/app/views/spree/api/credit_cards/_credit_card.json.jbuilder +1 -1
- data/app/views/spree/api/credit_cards/index.json.jbuilder +1 -1
- data/app/views/spree/api/customer_returns/index.json.jbuilder +2 -2
- data/app/views/spree/api/customer_returns/show.json.jbuilder +1 -1
- data/app/views/spree/api/errors/invalid_api_key.json.jbuilder +1 -1
- data/app/views/spree/api/images/_image.json.jbuilder +2 -2
- data/app/views/spree/api/inventory_units/show.json.jbuilder +1 -1
- data/app/views/spree/api/line_items/_line_item.json.jbuilder +2 -2
- data/app/views/spree/api/option_types/_option_type.json.jbuilder +2 -2
- data/app/views/spree/api/option_values/_option_value.json.jbuilder +1 -1
- data/app/views/spree/api/orders/_big.json.jbuilder +3 -3
- data/app/views/spree/api/orders/_order.json.jbuilder +1 -1
- data/app/views/spree/api/orders/index.json.jbuilder +1 -1
- data/app/views/spree/api/orders/mine.json.jbuilder +1 -1
- data/app/views/spree/api/payments/credit_over_limit.json.jbuilder +1 -1
- data/app/views/spree/api/payments/index.json.jbuilder +2 -2
- data/app/views/spree/api/payments/new.json.jbuilder +1 -1
- data/app/views/spree/api/payments/show.json.jbuilder +1 -1
- data/app/views/spree/api/payments/source_views/_gateway.json.jbuilder +1 -1
- data/app/views/spree/api/payments/source_views/_store_credit.json.jbuilder +1 -1
- data/app/views/spree/api/payments/update_forbidden.json.jbuilder +1 -1
- data/app/views/spree/api/product_properties/index.json.jbuilder +2 -2
- data/app/views/spree/api/product_properties/show.json.jbuilder +1 -1
- data/app/views/spree/api/products/_product.json.jbuilder +5 -5
- data/app/views/spree/api/products/index.json.jbuilder +1 -1
- data/app/views/spree/api/promotions/show.json.jbuilder +1 -1
- data/app/views/spree/api/properties/index.json.jbuilder +2 -2
- data/app/views/spree/api/properties/show.json.jbuilder +1 -1
- data/app/views/spree/api/return_authorizations/index.json.jbuilder +2 -2
- data/app/views/spree/api/return_authorizations/show.json.jbuilder +1 -1
- data/app/views/spree/api/shared/_pagination.json.jbuilder +4 -4
- data/app/views/spree/api/shipments/_big.json.jbuilder +7 -7
- data/app/views/spree/api/shipments/_small.json.jbuilder +4 -4
- data/app/views/spree/api/shipments/estimated_rates.json.jbuilder +1 -1
- data/app/views/spree/api/shipments/mine.json.jbuilder +1 -1
- data/app/views/spree/api/shipments/show.json.jbuilder +4 -4
- data/app/views/spree/api/shipping_rates/_shipping_rate.json.jbuilder +1 -1
- data/app/views/spree/api/states/index.json.jbuilder +2 -2
- data/app/views/spree/api/states/show.json.jbuilder +1 -1
- data/app/views/spree/api/stock_items/_stock_item.json.jbuilder +1 -1
- data/app/views/spree/api/stock_items/index.json.jbuilder +1 -1
- data/app/views/spree/api/stock_locations/_stock_location.json.jbuilder +3 -3
- data/app/views/spree/api/stock_locations/index.json.jbuilder +1 -1
- data/app/views/spree/api/stock_movements/_stock_movement.json.jbuilder +1 -1
- data/app/views/spree/api/stock_movements/index.json.jbuilder +1 -1
- data/app/views/spree/api/store_credit_events/mine.json.jbuilder +2 -2
- data/app/views/spree/api/stores/index.json.jbuilder +1 -1
- data/app/views/spree/api/stores/show.json.jbuilder +1 -1
- data/app/views/spree/api/taxonomies/_nested.json.jbuilder +3 -3
- data/app/views/spree/api/taxonomies/_taxonomy.json.jbuilder +3 -3
- data/app/views/spree/api/taxonomies/index.json.jbuilder +1 -1
- data/app/views/spree/api/taxons/_taxon.json.jbuilder +2 -2
- data/app/views/spree/api/taxons/_taxons.json.jbuilder +1 -1
- data/app/views/spree/api/taxons/index.json.jbuilder +2 -2
- data/app/views/spree/api/users/_user.json.jbuilder +1 -1
- data/app/views/spree/api/users/index.json.jbuilder +1 -1
- data/app/views/spree/api/variants/_big.json.jbuilder +3 -3
- data/app/views/spree/api/variants/_small.json.jbuilder +2 -2
- data/app/views/spree/api/variants/index.json.jbuilder +1 -1
- data/app/views/spree/api/zones/_zone.json.jbuilder +2 -2
- data/app/views/spree/api/zones/index.json.jbuilder +1 -1
- data/config/routes.rb +9 -9
- data/lib/solidus_api.rb +1 -1
- data/lib/spree/api/config.rb +1 -1
- data/lib/spree/api/engine.rb +4 -4
- data/lib/spree/api/responders.rb +2 -2
- data/lib/spree/api/testing_support/helpers.rb +3 -3
- data/lib/spree/api/testing_support/setup.rb +1 -1
- data/lib/spree/api.rb +2 -2
- data/lib/spree/api_configuration.rb +8 -8
- data/lib/spree_api.rb +3 -3
- data/solidus_api.gemspec +16 -16
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92ccd1baa7331139315707fd902eeec5712a41d6563f713611c4c4c32beaff34
|
|
4
|
+
data.tar.gz: 2b93ffdf94c871ec54eaabda3c9c4b46e5108283e1d2aa99686dba426e811cf2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d91812f69f054d0536f3bd0bc34a7c028ded3d4172917348d587fbeac25b2a5bb7e2eab28f38d6ae72f82a0a781137c4c53372005c876c42abaf6b115ba9a95f
|
|
7
|
+
data.tar.gz: 2eb2ce76ec4d4a9892f7fa3fd99691f81376cdb0580f8ca39c227ba2f7c394ddb25b14c7e1180cbe931ad0c7f8d5d4d297988b576eabe7f5ca2e70451bbbc920
|
data/Rakefile
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "rake"
|
|
5
|
+
require "rake/testtask"
|
|
6
|
+
require "rspec/core/rake_task"
|
|
7
|
+
require "spree/testing_support/dummy_app/rake_tasks"
|
|
8
|
+
require "bundler/gem_tasks"
|
|
9
9
|
|
|
10
10
|
RSpec::Core::RakeTask.new
|
|
11
11
|
task default: :spec
|
|
12
12
|
|
|
13
13
|
DummyApp::RakeTasks.new(
|
|
14
14
|
gem_root: File.expand_path(__dir__),
|
|
15
|
-
lib_name:
|
|
15
|
+
lib_name: "solidus_api"
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
task test_app:
|
|
18
|
+
task test_app: "db:reset"
|
|
@@ -15,11 +15,12 @@ module Spree
|
|
|
15
15
|
authorize! :update, @order, order_token
|
|
16
16
|
find_address
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
success = @order.update({"#{@order_source}_attributes" => address_params})
|
|
19
|
+
@address = @order.send(@order_source)
|
|
20
|
+
|
|
21
|
+
if success
|
|
20
22
|
respond_with(@address, default_template: :show)
|
|
21
23
|
else
|
|
22
|
-
@address = @order.send(@order_source)
|
|
23
24
|
invalid_resource!(@address)
|
|
24
25
|
end
|
|
25
26
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "spree/api/responders"
|
|
4
4
|
|
|
5
5
|
module Spree
|
|
6
6
|
module Api
|
|
@@ -19,7 +19,7 @@ module Spree
|
|
|
19
19
|
self.admin_line_item_attributes = [:price, :variant_id, :sku]
|
|
20
20
|
|
|
21
21
|
class_attribute :admin_metadata_attributes
|
|
22
|
-
self.admin_metadata_attributes = [{
|
|
22
|
+
self.admin_metadata_attributes = [{admin_metadata: {}}]
|
|
23
23
|
|
|
24
24
|
before_action :deprecated_load_user
|
|
25
25
|
before_action :authorize_for_order, if: proc { order_token.present? }
|
|
@@ -147,7 +147,7 @@ module Spree
|
|
|
147
147
|
def bearer_token
|
|
148
148
|
pattern = /^Bearer /
|
|
149
149
|
header = request.headers["Authorization"]
|
|
150
|
-
header.gsub(pattern,
|
|
150
|
+
header.gsub(pattern, "") if header.present? && header.match(pattern)
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
def order_token
|
|
@@ -175,7 +175,7 @@ module Spree
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
def variants_associations
|
|
178
|
-
[{
|
|
178
|
+
[{option_values: :option_type}, :prices, :images]
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
def product_includes
|
|
@@ -202,16 +202,16 @@ module Spree
|
|
|
202
202
|
render(
|
|
203
203
|
json: {
|
|
204
204
|
errors: [I18n.t(:quantity_is_not_available, scope: "spree.api.order")],
|
|
205
|
-
type:
|
|
205
|
+
type: "insufficient_stock"
|
|
206
206
|
},
|
|
207
207
|
status: :unprocessable_entity
|
|
208
208
|
)
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
def paginate(resource)
|
|
212
|
-
resource
|
|
213
|
-
page(params[:page])
|
|
214
|
-
per(params[:per_page] || default_per_page)
|
|
212
|
+
resource
|
|
213
|
+
.page(params[:page])
|
|
214
|
+
.per(params[:per_page] || default_per_page)
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
def default_per_page
|
|
@@ -221,7 +221,7 @@ module Spree
|
|
|
221
221
|
def invalid_transition(error)
|
|
222
222
|
logger.error("invalid_transition #{error.event} from #{error.from} for #{error.object.class.name}. Error: #{error.inspect}")
|
|
223
223
|
|
|
224
|
-
render "spree/api/errors/could_not_transition", locals: {
|
|
224
|
+
render "spree/api/errors/could_not_transition", locals: {resource: error.object}, status: :unprocessable_entity
|
|
225
225
|
end
|
|
226
226
|
end
|
|
227
227
|
end
|
|
@@ -16,26 +16,26 @@ module Spree
|
|
|
16
16
|
def next
|
|
17
17
|
authorize! :update, @order, order_token
|
|
18
18
|
if !expected_total_ok?(params[:expected_total])
|
|
19
|
-
respond_with(@order, default_template:
|
|
19
|
+
respond_with(@order, default_template: "spree/api/orders/expected_total_mismatch", status: 400)
|
|
20
20
|
return
|
|
21
21
|
end
|
|
22
22
|
@order.next!
|
|
23
|
-
respond_with(@order, default_template:
|
|
23
|
+
respond_with(@order, default_template: "spree/api/orders/show", status: 200)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def advance
|
|
27
27
|
authorize! :update, @order, order_token
|
|
28
28
|
@order.contents.advance
|
|
29
|
-
respond_with(@order, default_template:
|
|
29
|
+
respond_with(@order, default_template: "spree/api/orders/show", status: 200)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def complete
|
|
33
33
|
authorize! :update, @order, order_token
|
|
34
34
|
if !expected_total_ok?(params[:expected_total])
|
|
35
|
-
respond_with(@order, default_template:
|
|
35
|
+
respond_with(@order, default_template: "spree/api/orders/expected_total_mismatch", status: 400)
|
|
36
36
|
else
|
|
37
37
|
@order.complete!
|
|
38
|
-
respond_with(@order, default_template:
|
|
38
|
+
respond_with(@order, default_template: "spree/api/orders/show", status: 200)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -51,7 +51,7 @@ module Spree
|
|
|
51
51
|
|
|
52
52
|
if @order.completed? || @order.next!
|
|
53
53
|
state_callback(:after)
|
|
54
|
-
respond_with(@order, default_template:
|
|
54
|
+
respond_with(@order, default_template: "spree/api/orders/show")
|
|
55
55
|
end
|
|
56
56
|
else
|
|
57
57
|
invalid_resource!(@order)
|
|
@@ -6,11 +6,11 @@ module Spree
|
|
|
6
6
|
skip_before_action :authenticate_user
|
|
7
7
|
|
|
8
8
|
def index
|
|
9
|
-
@countries = Spree::Country
|
|
10
|
-
accessible_by(current_ability)
|
|
11
|
-
ransack(params[:q])
|
|
12
|
-
result
|
|
13
|
-
order(
|
|
9
|
+
@countries = Spree::Country
|
|
10
|
+
.accessible_by(current_ability)
|
|
11
|
+
.ransack(params[:q])
|
|
12
|
+
.result
|
|
13
|
+
.order("name ASC")
|
|
14
14
|
|
|
15
15
|
country = Spree::Country.order("updated_at ASC").last
|
|
16
16
|
|
|
@@ -13,10 +13,10 @@ module Spree
|
|
|
13
13
|
@handler = Spree::Config.promotions.coupon_code_handler_class.new(@order).apply
|
|
14
14
|
|
|
15
15
|
if @handler.successful?
|
|
16
|
-
render
|
|
16
|
+
render "spree/api/promotions/handler", status: 200
|
|
17
17
|
else
|
|
18
18
|
logger.error("apply_coupon_code_error=#{@handler.error.inspect}")
|
|
19
|
-
render
|
|
19
|
+
render "spree/api/promotions/handler", status: 422
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -27,10 +27,10 @@ module Spree
|
|
|
27
27
|
@handler = Spree::Config.promotions.coupon_code_handler_class.new(@order).remove
|
|
28
28
|
|
|
29
29
|
if @handler.successful?
|
|
30
|
-
render
|
|
30
|
+
render "spree/api/promotions/handler", status: 200
|
|
31
31
|
else
|
|
32
32
|
logger.error("remove_coupon_code_error=#{@handler.error.inspect}")
|
|
33
|
-
render
|
|
33
|
+
render "spree/api/promotions/handler", status: 422
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -22,11 +22,11 @@ module Spree
|
|
|
22
22
|
def index
|
|
23
23
|
authorize! :index, CustomerReturn
|
|
24
24
|
|
|
25
|
-
@customer_returns = @order
|
|
26
|
-
customer_returns
|
|
27
|
-
accessible_by(current_ability)
|
|
28
|
-
ransack(params[:q])
|
|
29
|
-
result
|
|
25
|
+
@customer_returns = @order
|
|
26
|
+
.customer_returns
|
|
27
|
+
.accessible_by(current_ability)
|
|
28
|
+
.ransack(params[:q])
|
|
29
|
+
.result
|
|
30
30
|
|
|
31
31
|
@customer_returns = paginate(@customer_returns)
|
|
32
32
|
|
|
@@ -66,17 +66,17 @@ module Spree
|
|
|
66
66
|
|
|
67
67
|
def build_customer_return
|
|
68
68
|
customer_return_attributes = customer_return_params
|
|
69
|
-
return_items_params = customer_return_attributes
|
|
70
|
-
delete(:return_items_attributes)
|
|
69
|
+
return_items_params = customer_return_attributes
|
|
70
|
+
.delete(:return_items_attributes)
|
|
71
71
|
|
|
72
72
|
@customer_return = CustomerReturn.new(customer_return_attributes)
|
|
73
73
|
|
|
74
74
|
@customer_return.return_items = return_items_params.map do |item_params|
|
|
75
75
|
return_item = if item_params[:id]
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
Spree::ReturnItem.find(item_params[:id])
|
|
77
|
+
else
|
|
78
|
+
Spree::ReturnItem.new
|
|
79
|
+
end
|
|
80
80
|
|
|
81
81
|
return_item.assign_attributes(item_params)
|
|
82
82
|
|
|
@@ -30,14 +30,14 @@ module Spree
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def prepare_event
|
|
33
|
-
return unless @event = params[:fire]
|
|
33
|
+
return unless (@event = params[:fire])
|
|
34
34
|
|
|
35
35
|
can_event = "can_#{@event}?"
|
|
36
36
|
|
|
37
37
|
unless inventory_unit.respond_to?(can_event) &&
|
|
38
|
-
|
|
39
|
-
render json: {
|
|
40
|
-
|
|
38
|
+
inventory_unit.send(can_event)
|
|
39
|
+
render json: {exception: "cannot transition to #{@event}"},
|
|
40
|
+
status: 200
|
|
41
41
|
false
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -55,16 +55,16 @@ module Spree
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def line_items_attributes
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
58
|
+
{line_items_attributes: {
|
|
59
|
+
id: params[:id],
|
|
60
|
+
quantity: params[:line_item][:quantity],
|
|
61
|
+
options: line_item_params[:options] || {},
|
|
62
|
+
**extract_metadata
|
|
63
|
+
}}
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def extract_metadata
|
|
67
|
-
metadata = {
|
|
67
|
+
metadata = {customer_metadata: line_item_params[:customer_metadata]}
|
|
68
68
|
|
|
69
69
|
if current_user_roles&.include?("admin")
|
|
70
70
|
metadata[:admin_metadata] = line_item_params[:admin_metadata]
|
|
@@ -4,10 +4,10 @@ module Spree
|
|
|
4
4
|
module Api
|
|
5
5
|
class OptionTypesController < Spree::Api::BaseController
|
|
6
6
|
def index
|
|
7
|
-
if params[:ids]
|
|
8
|
-
|
|
7
|
+
@option_types = if params[:ids]
|
|
8
|
+
Spree::OptionType.includes(:option_values).accessible_by(current_ability).where(id: params[:ids].split(","))
|
|
9
9
|
else
|
|
10
|
-
|
|
10
|
+
Spree::OptionType.includes(:option_values).accessible_by(current_ability).load.ransack(params[:q]).result
|
|
11
11
|
end
|
|
12
12
|
respond_with(@option_types)
|
|
13
13
|
end
|
|
@@ -4,10 +4,10 @@ module Spree
|
|
|
4
4
|
module Api
|
|
5
5
|
class OptionValuesController < Spree::Api::BaseController
|
|
6
6
|
def index
|
|
7
|
-
if params[:ids]
|
|
8
|
-
|
|
7
|
+
@option_values = if params[:ids]
|
|
8
|
+
scope.where(id: params[:ids])
|
|
9
9
|
else
|
|
10
|
-
|
|
10
|
+
scope.ransack(params[:q]).result.distinct
|
|
11
11
|
end
|
|
12
12
|
respond_with(@option_values)
|
|
13
13
|
end
|
|
@@ -45,10 +45,10 @@ module Spree
|
|
|
45
45
|
private
|
|
46
46
|
|
|
47
47
|
def scope
|
|
48
|
-
if params[:option_type_id]
|
|
49
|
-
|
|
48
|
+
@scope ||= if params[:option_type_id]
|
|
49
|
+
Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability)
|
|
50
50
|
else
|
|
51
|
-
|
|
51
|
+
Spree::OptionValue.accessible_by(current_ability).load
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -11,6 +11,12 @@ module Spree
|
|
|
11
11
|
|
|
12
12
|
class_attribute :admin_payment_attributes
|
|
13
13
|
self.admin_payment_attributes = [:payment_method, :amount, :state, source: {}]
|
|
14
|
+
msg = "`Spree::Api::OrdersController.admin_payment_attributes` is deprecated."
|
|
15
|
+
deprecate(
|
|
16
|
+
admin_payment_attributes: msg,
|
|
17
|
+
"admin_payment_attributes=": msg,
|
|
18
|
+
deprecator: Spree.deprecator
|
|
19
|
+
)
|
|
14
20
|
|
|
15
21
|
before_action :find_order, except: [:create, :mine, :current, :index]
|
|
16
22
|
around_action :lock_order, except: [:create, :mine, :current, :index, :show]
|
|
@@ -58,7 +64,7 @@ module Spree
|
|
|
58
64
|
def index
|
|
59
65
|
authorize! :admin, Order
|
|
60
66
|
orders_includes = [
|
|
61
|
-
{
|
|
67
|
+
{user: :store_credits},
|
|
62
68
|
:line_items,
|
|
63
69
|
:valid_store_credit_payments
|
|
64
70
|
]
|
|
@@ -91,8 +97,8 @@ module Spree
|
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
def current
|
|
94
|
-
if current_api_user && @order = current_api_user.last_incomplete_spree_order(store: current_store)
|
|
95
|
-
respond_with(@order, default_template: :show, locals: {
|
|
100
|
+
if current_api_user && (@order = current_api_user.last_incomplete_spree_order(store: current_store))
|
|
101
|
+
respond_with(@order, default_template: :show, locals: {root_object: @order})
|
|
96
102
|
else
|
|
97
103
|
head :no_content
|
|
98
104
|
end
|
|
@@ -122,7 +128,7 @@ module Spree
|
|
|
122
128
|
def prevent_customer_metadata_update
|
|
123
129
|
return unless @order&.completed? && cannot?(:admin, Spree::Order)
|
|
124
130
|
|
|
125
|
-
params[:order]
|
|
131
|
+
params[:order]&.delete(:customer_metadata)
|
|
126
132
|
end
|
|
127
133
|
|
|
128
134
|
def normalize_params
|
|
@@ -149,7 +155,25 @@ module Spree
|
|
|
149
155
|
end
|
|
150
156
|
|
|
151
157
|
def permitted_order_attributes
|
|
152
|
-
can?(:admin, Spree::Order)
|
|
158
|
+
if can?(:admin, Spree::Order)
|
|
159
|
+
super + admin_order_attributes
|
|
160
|
+
else
|
|
161
|
+
# We need to remove the `:amount` attribute from payments_attributes
|
|
162
|
+
# for non-admin users. Unfortunately, order_attributes uses the
|
|
163
|
+
# checkout_payment_attributes instead of the payment_attributes, which
|
|
164
|
+
# needs to be able to set the amount.
|
|
165
|
+
#
|
|
166
|
+
# We're doing a deep_dup here to avoid modifying the original
|
|
167
|
+
# permitted attributes, which could have unintended side effects.
|
|
168
|
+
order_attributes = super.deep_dup
|
|
169
|
+
|
|
170
|
+
payments_attributes = order_attributes.find do |attribute|
|
|
171
|
+
attribute.is_a?(Hash) && attribute.has_key?(:payments_attributes)
|
|
172
|
+
end
|
|
173
|
+
payments_attributes[:payments_attributes] -= [:amount]
|
|
174
|
+
|
|
175
|
+
order_attributes
|
|
176
|
+
end
|
|
153
177
|
end
|
|
154
178
|
|
|
155
179
|
def permitted_shipment_attributes
|
|
@@ -161,6 +185,12 @@ module Spree
|
|
|
161
185
|
end
|
|
162
186
|
|
|
163
187
|
def permitted_payment_attributes
|
|
188
|
+
Spree.deprecator.warn(
|
|
189
|
+
"`Spree::Api::OrdersController#permitted_payment_attributes` is deprecated. " \
|
|
190
|
+
"This method was never actually used in this controller because " \
|
|
191
|
+
"permitted_order_attributes uses the permitted_checkout_payment_attributes " \
|
|
192
|
+
"method to determine the permitted attributes for payments."
|
|
193
|
+
)
|
|
164
194
|
if can?(:admin, Spree::Payment)
|
|
165
195
|
super + admin_payment_attributes
|
|
166
196
|
else
|
|
@@ -169,13 +199,13 @@ module Spree
|
|
|
169
199
|
end
|
|
170
200
|
|
|
171
201
|
def find_order(_lock = false)
|
|
172
|
-
@order = Spree::Order
|
|
173
|
-
includes(line_items: [:adjustments, {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
find_by!(number: params[:id])
|
|
202
|
+
@order = Spree::Order
|
|
203
|
+
.includes(line_items: [:adjustments, {variant: :images}],
|
|
204
|
+
payments: :payment_method,
|
|
205
|
+
shipments: {
|
|
206
|
+
shipping_rates: {shipping_method: :zones, taxes: :tax_rate}
|
|
207
|
+
})
|
|
208
|
+
.find_by!(number: params[:id])
|
|
179
209
|
end
|
|
180
210
|
|
|
181
211
|
def order_id
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
module Spree
|
|
4
4
|
module Api
|
|
5
5
|
class PaymentsController < Spree::Api::BaseController
|
|
6
|
+
class_attribute :admin_payment_attributes
|
|
7
|
+
self.admin_payment_attributes = [:amount]
|
|
8
|
+
|
|
6
9
|
before_action :find_order
|
|
7
10
|
around_action :lock_order, only: [:create, :update, :authorize, :capture, :purchase, :void]
|
|
8
11
|
before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void]
|
|
@@ -30,7 +33,7 @@ module Spree
|
|
|
30
33
|
def update
|
|
31
34
|
authorize! params[:action], @payment
|
|
32
35
|
if !@payment.pending?
|
|
33
|
-
render
|
|
36
|
+
render "update_forbidden", status: 403
|
|
34
37
|
elsif @payment.update(payment_params)
|
|
35
38
|
respond_with(@payment, default_template: :show)
|
|
36
39
|
else
|
|
@@ -78,6 +81,14 @@ module Spree
|
|
|
78
81
|
def payment_params
|
|
79
82
|
params.require(:payment).permit(permitted_payment_attributes)
|
|
80
83
|
end
|
|
84
|
+
|
|
85
|
+
def permitted_payment_attributes
|
|
86
|
+
if can?(:admin, Spree::Payment)
|
|
87
|
+
super + admin_payment_attributes
|
|
88
|
+
else
|
|
89
|
+
super
|
|
90
|
+
end
|
|
91
|
+
end
|
|
81
92
|
end
|
|
82
93
|
end
|
|
83
94
|
end
|
|
@@ -7,11 +7,11 @@ module Spree
|
|
|
7
7
|
before_action :product_property, only: [:show, :update, :destroy]
|
|
8
8
|
|
|
9
9
|
def index
|
|
10
|
-
@product_properties = @product
|
|
11
|
-
product_properties
|
|
12
|
-
accessible_by(current_ability)
|
|
13
|
-
ransack(params[:q])
|
|
14
|
-
result
|
|
10
|
+
@product_properties = @product
|
|
11
|
+
.product_properties
|
|
12
|
+
.accessible_by(current_ability)
|
|
13
|
+
.ransack(params[:q])
|
|
14
|
+
.result
|
|
15
15
|
|
|
16
16
|
@product_properties = paginate(@product_properties)
|
|
17
17
|
|
|
@@ -60,7 +60,7 @@ module Spree
|
|
|
60
60
|
def product_property
|
|
61
61
|
if @product
|
|
62
62
|
@product_property ||= @product.product_properties.find_by(id: params[:id])
|
|
63
|
-
@product_property ||= @product.product_properties.includes(:property).where(spree_properties: {
|
|
63
|
+
@product_property ||= @product.product_properties.includes(:property).where(spree_properties: {name: params[:id]}).first!
|
|
64
64
|
authorize! :show, @product_property
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -12,17 +12,17 @@ module Spree
|
|
|
12
12
|
:variants,
|
|
13
13
|
:option_types,
|
|
14
14
|
:product_properties,
|
|
15
|
-
{
|
|
15
|
+
{classifications: :taxon}
|
|
16
16
|
]
|
|
17
17
|
@products = product_scope
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
.ransack(params[:q])
|
|
19
|
+
.result
|
|
20
|
+
.includes(products_includes)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
@products = paginate(@products.distinct)
|
|
24
24
|
expires_in 15.minutes, public: true
|
|
25
|
-
headers[
|
|
25
|
+
headers["Surrogate-Control"] = "max-age=#{15.minutes}"
|
|
26
26
|
respond_with(@products)
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -32,8 +32,8 @@ module Spree
|
|
|
32
32
|
def show
|
|
33
33
|
@product = find_product(params[:id])
|
|
34
34
|
expires_in 15.minutes, public: true
|
|
35
|
-
headers[
|
|
36
|
-
headers[
|
|
35
|
+
headers["Surrogate-Control"] = "max-age=#{15.minutes}"
|
|
36
|
+
headers["Surrogate-Key"] = "product_id=1"
|
|
37
37
|
respond_with(@product)
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -75,7 +75,7 @@ module Spree
|
|
|
75
75
|
params[:product][:available_on] ||= Time.current
|
|
76
76
|
set_up_shipping_category
|
|
77
77
|
|
|
78
|
-
options = {
|
|
78
|
+
options = {variants_attrs: variants_params, options_attrs: option_types_params}
|
|
79
79
|
@product = Core::Importer::Product.new(nil, product_params, options).create
|
|
80
80
|
|
|
81
81
|
if @product.persisted?
|
|
@@ -89,7 +89,7 @@ module Spree
|
|
|
89
89
|
@product = find_product(params[:id])
|
|
90
90
|
authorize! :update, @product
|
|
91
91
|
|
|
92
|
-
options = {
|
|
92
|
+
options = {variants_attrs: variants_params, options_attrs: option_types_params}
|
|
93
93
|
@product = Core::Importer::Product.new(@product, product_params, options).update
|
|
94
94
|
|
|
95
95
|
if @product.errors.empty?
|
|
@@ -111,7 +111,7 @@ module Spree
|
|
|
111
111
|
def product_params
|
|
112
112
|
product_params = params.require(:product).permit(permitted_product_attributes)
|
|
113
113
|
if product_params[:taxon_ids].present?
|
|
114
|
-
product_params[:taxon_ids] = product_params[:taxon_ids].split(
|
|
114
|
+
product_params[:taxon_ids] = product_params[:taxon_ids].split(",")
|
|
115
115
|
end
|
|
116
116
|
product_params
|
|
117
117
|
end
|
|
@@ -133,7 +133,7 @@ module Spree
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
def set_up_shipping_category
|
|
136
|
-
if shipping_category = params[:product].delete(:shipping_category)
|
|
136
|
+
if (shipping_category = params[:product].delete(:shipping_category))
|
|
137
137
|
id = Spree::ShippingCategory.find_or_create_by(name: shipping_category).id
|
|
138
138
|
params[:product][:shipping_category_id] = id
|
|
139
139
|
end
|
|
@@ -27,11 +27,11 @@ module Spree
|
|
|
27
27
|
def index
|
|
28
28
|
authorize! :admin, ReturnAuthorization
|
|
29
29
|
|
|
30
|
-
@return_authorizations = @order
|
|
31
|
-
return_authorizations
|
|
32
|
-
accessible_by(current_ability)
|
|
33
|
-
ransack(params[:q])
|
|
34
|
-
result
|
|
30
|
+
@return_authorizations = @order
|
|
31
|
+
.return_authorizations
|
|
32
|
+
.accessible_by(current_ability)
|
|
33
|
+
.ransack(params[:q])
|
|
34
|
+
.result
|
|
35
35
|
|
|
36
36
|
@return_authorizations = paginate(@return_authorizations)
|
|
37
37
|
|
|
@@ -14,7 +14,7 @@ module Spree
|
|
|
14
14
|
@shipments = Spree::Shipment
|
|
15
15
|
.reverse_chronological
|
|
16
16
|
.joins(:order)
|
|
17
|
-
.where(spree_orders: {
|
|
17
|
+
.where(spree_orders: {user_id: current_api_user.id})
|
|
18
18
|
.includes(mine_includes)
|
|
19
19
|
.ransack(params[:q]).result
|
|
20
20
|
|
|
@@ -57,7 +57,7 @@ module Spree
|
|
|
57
57
|
@shipment.ready!
|
|
58
58
|
else
|
|
59
59
|
logger.error("cannot_ready_shipment shipment_state=#{@shipment.state}")
|
|
60
|
-
render(
|
|
60
|
+
render("spree/api/shipments/cannot_ready_shipment", status: 422) && return
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
respond_with(@shipment, default_template: :show)
|
|
@@ -66,7 +66,7 @@ module Spree
|
|
|
66
66
|
def ship
|
|
67
67
|
authorize! :ship, @shipment
|
|
68
68
|
unless @shipment.shipped?
|
|
69
|
-
@shipment.suppress_mailer = (params[:send_mailer] ==
|
|
69
|
+
@shipment.suppress_mailer = (params[:send_mailer] == "false")
|
|
70
70
|
@shipment.ship!
|
|
71
71
|
end
|
|
72
72
|
respond_with(@shipment, default_template: :show)
|
|
@@ -75,7 +75,7 @@ module Spree
|
|
|
75
75
|
def add
|
|
76
76
|
quantity = params[:quantity].to_i
|
|
77
77
|
|
|
78
|
-
@shipment.order.contents.add(variant, quantity, {
|
|
78
|
+
@shipment.order.contents.add(variant, quantity, {shipment: @shipment})
|
|
79
79
|
respond_with(@shipment, default_template: :show)
|
|
80
80
|
end
|
|
81
81
|
|
|
@@ -86,7 +86,7 @@ module Spree
|
|
|
86
86
|
@shipment.errors.add(:base, :cannot_remove_items_shipment_state, state: @shipment.state)
|
|
87
87
|
invalid_resource!(@shipment)
|
|
88
88
|
else
|
|
89
|
-
@shipment.order.contents.remove(variant, quantity, {
|
|
89
|
+
@shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
|
|
90
90
|
@shipment.reload if @shipment.persisted?
|
|
91
91
|
respond_with(@shipment, default_template: :show)
|
|
92
92
|
end
|
|
@@ -110,19 +110,19 @@ module Spree
|
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
if fulfilment_changer.run!
|
|
113
|
-
render json: {
|
|
113
|
+
render json: {success: true, message: t("spree.api.shipment.transfer_success")}, status: :accepted
|
|
114
114
|
else
|
|
115
|
-
render json: {
|
|
115
|
+
render json: {success: false, message: fulfilment_changer.errors.full_messages.to_sentence}, status: :accepted
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
private
|
|
120
120
|
|
|
121
121
|
def load_transfer_params
|
|
122
|
-
@original_shipment
|
|
123
|
-
@order
|
|
124
|
-
@variant
|
|
125
|
-
@quantity
|
|
122
|
+
@original_shipment = Spree::Shipment.find_by!(number: params[:original_shipment_number])
|
|
123
|
+
@order = @original_shipment.order
|
|
124
|
+
@variant = Spree::Variant.find(params[:variant_id])
|
|
125
|
+
@quantity = params[:quantity].to_i
|
|
126
126
|
authorize! [:update, :destroy], @original_shipment
|
|
127
127
|
authorize! :create, Shipment
|
|
128
128
|
end
|