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.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +9 -12
- data/app/controllers/spree/api/checkouts_controller.rb +3 -5
- data/app/controllers/spree/api/orders_controller.rb +2 -12
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/app/controllers/spree/api/resource_controller.rb +2 -0
- data/app/controllers/spree/api/shipments_controller.rb +17 -6
- data/app/controllers/spree/api/stock_items_controller.rb +6 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -4
- data/app/views/.rubocop.yml +4 -0
- data/app/views/spree/api/address_books/show.json.jbuilder +11 -0
- data/app/views/spree/api/addresses/_address.json.jbuilder +17 -0
- data/app/views/spree/api/addresses/show.json.jbuilder +1 -0
- data/app/views/spree/api/adjustments/_adjustment.json.jbuilder +4 -0
- data/app/views/spree/api/config/money.json.jbuilder +1 -0
- data/app/views/spree/api/config/show.json.jbuilder +2 -0
- data/app/views/spree/api/countries/index.json.jbuilder +2 -0
- data/app/views/spree/api/countries/show.json.jbuilder +4 -0
- data/app/views/spree/api/credit_cards/_credit_card.json.jbuilder +10 -0
- data/app/views/spree/api/credit_cards/index.json.jbuilder +4 -0
- data/app/views/spree/api/credit_cards/show.json.jbuilder +1 -0
- data/app/views/spree/api/errors/delete_restriction.json.jbuilder +1 -0
- data/app/views/spree/api/errors/gateway_error.json.jbuilder +1 -0
- data/app/views/spree/api/errors/invalid_api_key.json.jbuilder +1 -0
- data/app/views/spree/api/errors/invalid_resource.json.jbuilder +2 -0
- data/app/views/spree/api/errors/must_specify_api_key.json.jbuilder +1 -0
- data/app/views/spree/api/errors/not_found.json.jbuilder +1 -0
- data/app/views/spree/api/errors/unauthorized.json.jbuilder +1 -0
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +1 -0
- data/app/views/spree/api/images/_image.json.jbuilder +5 -0
- data/app/views/spree/api/images/index.json.jbuilder +3 -0
- data/app/views/spree/api/images/show.json.jbuilder +1 -0
- data/app/views/spree/api/inventory_units/show.json.jbuilder +1 -0
- data/app/views/spree/api/line_items/_line_item.json.jbuilder +16 -0
- data/app/views/spree/api/line_items/new.json.jbuilder +2 -0
- data/app/views/spree/api/line_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/option_types/_option_type.json.jbuilder +4 -0
- data/app/views/spree/api/option_types/index.json.jbuilder +3 -0
- data/app/views/spree/api/option_types/show.json.jbuilder +1 -0
- data/app/views/spree/api/option_values/_option_value.json.jbuilder +1 -0
- data/app/views/spree/api/option_values/index.json.jbuilder +3 -0
- data/app/views/spree/api/option_values/show.json.jbuilder +1 -0
- data/app/views/spree/api/orders/_big.json.jbuilder +49 -0
- data/app/views/spree/api/orders/_order.json.jbuilder +10 -0
- data/app/views/spree/api/orders/could_not_apply_coupon.json.jbuilder +1 -0
- data/app/views/spree/api/orders/could_not_transition.json.jbuilder +2 -0
- data/app/views/spree/api/orders/expected_total_mismatch.json.jbuilder +1 -0
- data/app/views/spree/api/orders/index.json.jbuilder +4 -0
- data/app/views/spree/api/orders/invalid_shipping_method.json.jbuilder +1 -0
- data/app/views/spree/api/orders/mine.json.jbuilder +4 -0
- data/app/views/spree/api/orders/show.json.jbuilder +1 -0
- data/app/views/spree/api/payments/credit_over_limit.json.jbuilder +1 -0
- data/app/views/spree/api/payments/index.json.jbuilder +2 -0
- data/app/views/spree/api/payments/new.json.jbuilder +4 -0
- data/app/views/spree/api/payments/show.json.jbuilder +1 -0
- data/app/views/spree/api/payments/update_forbidden.json.jbuilder +1 -0
- data/app/views/spree/api/product_properties/index.json.jbuilder +4 -0
- data/app/views/spree/api/product_properties/new.json.jbuilder +2 -0
- data/app/views/spree/api/product_properties/show.json.jbuilder +1 -0
- data/app/views/spree/api/products/_product.json.jbuilder +34 -0
- data/app/views/spree/api/products/index.json.jbuilder +4 -0
- data/app/views/spree/api/products/new.json.jbuilder +2 -0
- data/app/views/spree/api/products/show.json.jbuilder +1 -0
- data/app/views/spree/api/promotions/handler.json.jbuilder +4 -0
- data/app/views/spree/api/promotions/show.json.jbuilder +1 -0
- data/app/views/spree/api/properties/index.json.jbuilder +4 -0
- data/app/views/spree/api/properties/new.json.jbuilder +2 -0
- data/app/views/spree/api/properties/show.json.jbuilder +1 -0
- data/app/views/spree/api/return_authorizations/index.json.jbuilder +4 -0
- data/app/views/spree/api/return_authorizations/new.json.jbuilder +2 -0
- data/app/views/spree/api/return_authorizations/show.json.jbuilder +1 -0
- data/app/views/spree/api/shared/_pagination.json.jbuilder +5 -0
- data/app/views/spree/api/shipments/_big.json.jbuilder +51 -0
- data/app/views/spree/api/shipments/_small.json.jbuilder +32 -0
- data/app/views/spree/api/shipments/cannot_ready_shipment.json.jbuilder +1 -0
- data/app/views/spree/api/shipments/mine.json.jbuilder +4 -0
- data/app/views/spree/api/shipments/show.json.jbuilder +31 -0
- data/app/views/spree/api/shipping_rates/_shipping_rate.json.jbuilder +2 -0
- data/app/views/spree/api/states/index.json.jbuilder +5 -0
- data/app/views/spree/api/states/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_items/_stock_item.json.jbuilder +4 -0
- data/app/views/spree/api/stock_items/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_locations/_stock_location.json.jbuilder +15 -0
- data/app/views/spree/api/stock_locations/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_locations/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_movements/_stock_movement.json.jbuilder +4 -0
- data/app/views/spree/api/stock_movements/index.json.jbuilder +4 -0
- data/app/views/spree/api/stock_movements/show.json.jbuilder +1 -0
- data/app/views/spree/api/stock_transfers/receive.json.jbuilder +4 -0
- data/app/views/spree/api/store_credit_events/mine.json.jbuilder +5 -0
- data/app/views/spree/api/stores/index.json.jbuilder +1 -0
- data/app/views/spree/api/stores/show.json.jbuilder +1 -0
- data/app/views/spree/api/taxonomies/_nested.json.jbuilder +8 -0
- data/app/views/spree/api/taxonomies/_taxonomy.json.jbuilder +11 -0
- data/app/views/spree/api/taxonomies/index.json.jbuilder +4 -0
- data/app/views/spree/api/taxonomies/jstree.json.jbuilder +6 -0
- data/app/views/spree/api/taxonomies/new.json.jbuilder +2 -0
- data/app/views/spree/api/taxonomies/show.json.jbuilder +1 -0
- data/app/views/spree/api/taxons/_taxon.json.jbuilder +2 -0
- data/app/views/spree/api/taxons/_taxons.json.jbuilder +4 -0
- data/app/views/spree/api/taxons/index.json.jbuilder +7 -0
- data/app/views/spree/api/taxons/jstree.json.jbuilder +8 -0
- data/app/views/spree/api/taxons/new.json.jbuilder +2 -0
- data/app/views/spree/api/taxons/show.json.jbuilder +1 -0
- data/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +5 -0
- data/app/views/spree/api/transfer_items/show.json.jbuilder +1 -0
- data/app/views/spree/api/users/_user.json.jbuilder +15 -0
- data/app/views/spree/api/users/index.json.jbuilder +4 -0
- data/app/views/spree/api/users/new.json.jbuilder +2 -0
- data/app/views/spree/api/users/show.json.jbuilder +1 -0
- data/app/views/spree/api/variants/_big.json.jbuilder +13 -0
- data/app/views/spree/api/variants/_small.json.jbuilder +16 -0
- data/app/views/spree/api/variants/index.json.jbuilder +4 -0
- data/app/views/spree/api/variants/new.json.jbuilder +2 -0
- data/app/views/spree/api/variants/show.json.jbuilder +1 -0
- data/app/views/spree/api/zones/_zone.json.jbuilder +4 -0
- data/app/views/spree/api/zones/index.json.jbuilder +4 -0
- data/app/views/spree/api/zones/show.json.jbuilder +1 -0
- data/config/locales/en.yml +1 -0
- data/lib/spree/api/engine.rb +0 -14
- data/lib/spree/api.rb +1 -1
- data/lib/spree_api.rb +1 -0
- data/solidus_api.gemspec +3 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +0 -56
- data/spec/requests/spree/api/checkouts_controller_spec.rb +8 -13
- data/spec/requests/spree/api/orders_controller_spec.rb +7 -60
- data/spec/requests/spree/api/payments_controller_spec.rb +0 -11
- data/spec/requests/spree/api/shipments_controller_spec.rb +16 -1
- data/spec/requests/spree/api/states_controller_spec.rb +1 -0
- data/spec/requests/spree/api/taxons_controller_spec.rb +25 -0
- data/spec/requests/spree/api/users_controller_spec.rb +1 -1
- data/spec/support/be_paginated_matcher.rb +7 -0
- data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +1 -0
- data/spec/test_views/spree/api/widgets/index.json.jbuilder +7 -0
- data/spec/test_views/spree/api/widgets/new.json.jbuilder +1 -0
- data/spec/test_views/spree/api/widgets/show.json.jbuilder +1 -0
- metadata +166 -111
- data/app/views/spree/api/address_books/show.v1.rabl +0 -7
- data/app/views/spree/api/addresses/show.v1.rabl +0 -10
- data/app/views/spree/api/adjustments/show.v1.rabl +0 -4
- data/app/views/spree/api/config/money.v1.rabl +0 -2
- data/app/views/spree/api/config/show.v1.rabl +0 -3
- data/app/views/spree/api/countries/index.v1.rabl +0 -7
- data/app/views/spree/api/countries/show.v1.rabl +0 -5
- data/app/views/spree/api/credit_cards/index.v1.rabl +0 -7
- data/app/views/spree/api/credit_cards/show.v1.rabl +0 -7
- data/app/views/spree/api/errors/gateway_error.v1.rabl +0 -2
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +0 -2
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +0 -3
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +0 -2
- data/app/views/spree/api/errors/not_found.v1.rabl +0 -2
- data/app/views/spree/api/errors/unauthorized.v1.rabl +0 -2
- data/app/views/spree/api/errors/variant_not_in_stock_transfer.v1.rabl +0 -2
- data/app/views/spree/api/images/index.v1.rabl +0 -4
- data/app/views/spree/api/images/show.v1.rabl +0 -6
- data/app/views/spree/api/inventory_units/show.rabl +0 -2
- data/app/views/spree/api/line_items/new.v1.rabl +0 -3
- data/app/views/spree/api/line_items/show.v1.rabl +0 -15
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_types/show.v1.rabl +0 -5
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/show.v1.rabl +0 -2
- data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +0 -2
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +0 -3
- data/app/views/spree/api/orders/expected_total_mismatch.v1.rabl +0 -2
- data/app/views/spree/api/orders/index.v1.rabl +0 -7
- data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +0 -2
- data/app/views/spree/api/orders/mine.v1.rabl +0 -9
- data/app/views/spree/api/orders/order.v1.rabl +0 -9
- data/app/views/spree/api/orders/show.v1.rabl +0 -53
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +0 -2
- data/app/views/spree/api/payments/index.v1.rabl +0 -7
- data/app/views/spree/api/payments/new.v1.rabl +0 -5
- data/app/views/spree/api/payments/show.v1.rabl +0 -2
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
- data/app/views/spree/api/product_properties/index.v1.rabl +0 -7
- data/app/views/spree/api/product_properties/new.v1.rabl +0 -2
- data/app/views/spree/api/product_properties/show.v1.rabl +0 -2
- data/app/views/spree/api/products/index.v1.rabl +0 -9
- data/app/views/spree/api/products/new.v1.rabl +0 -3
- data/app/views/spree/api/products/product.v1.rabl +0 -1
- data/app/views/spree/api/products/show.v1.rabl +0 -42
- data/app/views/spree/api/promotions/handler.v1.rabl +0 -5
- data/app/views/spree/api/promotions/show.v1.rabl +0 -2
- data/app/views/spree/api/properties/index.v1.rabl +0 -7
- data/app/views/spree/api/properties/new.v1.rabl +0 -2
- data/app/views/spree/api/properties/show.v1.rabl +0 -2
- data/app/views/spree/api/return_authorizations/index.v1.rabl +0 -7
- data/app/views/spree/api/return_authorizations/new.v1.rabl +0 -3
- data/app/views/spree/api/return_authorizations/show.v1.rabl +0 -2
- data/app/views/spree/api/shipments/big.v1.rabl +0 -55
- data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +0 -2
- data/app/views/spree/api/shipments/mine.v1.rabl +0 -9
- data/app/views/spree/api/shipments/show.v1.rabl +0 -32
- data/app/views/spree/api/shipments/small.v1.rabl +0 -37
- data/app/views/spree/api/shipping_rates/show.v1.rabl +0 -2
- data/app/views/spree/api/states/index.v1.rabl +0 -14
- data/app/views/spree/api/states/show.v1.rabl +0 -2
- data/app/views/spree/api/stock_items/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_items/show.v1.rabl +0 -5
- data/app/views/spree/api/stock_locations/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_locations/show.v1.rabl +0 -8
- data/app/views/spree/api/stock_movements/index.v1.rabl +0 -7
- data/app/views/spree/api/stock_movements/show.v1.rabl +0 -5
- data/app/views/spree/api/stock_transfers/receive.v1.rabl +0 -5
- data/app/views/spree/api/store_credit_events/mine.v1.rabl +0 -10
- data/app/views/spree/api/stores/index.v1.rabl +0 -4
- data/app/views/spree/api/stores/show.v1.rabl +0 -2
- data/app/views/spree/api/taxonomies/index.v1.rabl +0 -7
- data/app/views/spree/api/taxonomies/jstree.rabl +0 -8
- data/app/views/spree/api/taxonomies/nested.v1.rabl +0 -11
- data/app/views/spree/api/taxonomies/new.v1.rabl +0 -3
- data/app/views/spree/api/taxonomies/show.v1.rabl +0 -15
- data/app/views/spree/api/taxons/index.v1.rabl +0 -12
- data/app/views/spree/api/taxons/jstree.rabl +0 -8
- data/app/views/spree/api/taxons/new.v1.rabl +0 -3
- data/app/views/spree/api/taxons/show.v1.rabl +0 -6
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
- data/app/views/spree/api/transfer_items/show.v1.rabl +0 -6
- data/app/views/spree/api/users/index.v1.rabl +0 -7
- data/app/views/spree/api/users/new.v1.rabl +0 -3
- data/app/views/spree/api/users/show.v1.rabl +0 -10
- data/app/views/spree/api/variants/big.v1.rabl +0 -20
- data/app/views/spree/api/variants/index.v1.rabl +0 -9
- data/app/views/spree/api/variants/new.v1.rabl +0 -2
- data/app/views/spree/api/variants/show.v1.rabl +0 -3
- data/app/views/spree/api/variants/small.v1.rabl +0 -17
- data/app/views/spree/api/zones/index.v1.rabl +0 -7
- data/app/views/spree/api/zones/show.v1.rabl +0 -6
- data/config/initializers/rails5_rabl_hacks.rb +0 -12
- data/spec/test_views/spree/api/widgets/index.v1.rabl +0 -7
- data/spec/test_views/spree/api/widgets/new.v1.rabl +0 -2
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5be6f6cc794cc0b05b877514c744c20dd9c2526d
|
4
|
+
data.tar.gz: 85a853cdb5bc1c4f82f6db59680c9798ca4177b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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)
|
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
|
-
|
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
|
@@ -81,15 +81,26 @@ module Spree
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def transfer_to_location
|
84
|
-
@
|
85
|
-
@original_shipment.
|
86
|
-
|
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
|
-
@
|
91
|
-
|
92
|
-
|
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, :
|
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
|
-
:
|
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, :
|
161
|
+
:id, :count_on_hand, :backorderable, :stock_location_id,
|
163
162
|
:variant_id
|
164
163
|
]
|
165
164
|
|
@@ -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 @@
|
|
1
|
+
json.symbol(::Money.new(1, Spree::Config[:currency]).symbol)
|
@@ -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 @@
|
|
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 @@
|
|
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 @@
|
|
1
|
+
json.partial!("spree/api/line_items/line_item", line_item: @line_item)
|
@@ -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 @@
|
|
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 @@
|
|
1
|
+
json.errors(expected_total: [I18n.t(:expected_total_mismatch, scope: "spree.api.order")])
|
@@ -0,0 +1 @@
|
|
1
|
+
json.errors([I18n.t(:invalid_shipping_method, scope: "spree.api.order")])
|
@@ -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 @@
|
|
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 @@
|
|
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 @@
|
|
1
|
+
json.partial!("spree/api/products/product", product: @product)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.(@promotion, *promotion_attributes)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.(@property, *property_attributes)
|
@@ -0,0 +1 @@
|
|
1
|
+
json.(@return_authorization, *return_authorization_attributes)
|