solidus_api 3.0.0.rc2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +6 -3
- data/app/controllers/spree/api/customer_returns_controller.rb +30 -1
- data/app/controllers/spree/api/shipments_controller.rb +1 -1
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +1 -1
- data/app/helpers/spree/api/api_helpers.rb +13 -134
- data/app/views/spree/api/products/_product.json.jbuilder +2 -2
- data/app/views/spree/api/variants/_small.json.jbuilder +2 -2
- data/lib/spree/api/engine.rb +4 -0
- data/lib/spree/api_configuration.rb +128 -0
- data/openapi/main.hub.yml +3 -3
- data/openapi/pagination-and-filtering.md +23 -0
- data/openapi/solidus-api.oas.yml +1130 -361
- metadata +6 -6
- data/openapi/pagination.md +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95754df420b9b7e750d09379a5daed863451bb18fa0db4d74c30b8777fd7992f
|
4
|
+
data.tar.gz: b3d3f3692c91d9da3150269f2b0a86faab31b7e00034829f82067a6ad9b8c9f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 749a592b19194444127974f8f059256599c05137f9f5846221297fd6a8a92a2a2e4374c19fa91dfa061ed9fee1e38f9da219a59293b0a033bec8a93c172f9cd0
|
7
|
+
data.tar.gz: bc5947619160f92268d614f2723b5a36464ba0d1e1dcc025b169e6181649a02c0548392e270eec5c9a1eb402bf00b5ddae3a718de1e24d073f3f0fd58030e1bd
|
@@ -71,8 +71,11 @@ module Spree
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def gateway_error(exception)
|
74
|
-
|
75
|
-
|
74
|
+
# Fall back to a blank order if one isn't set, as we only need this for
|
75
|
+
# its errors interface.
|
76
|
+
model = @order || Spree::Order.new
|
77
|
+
model.errors.add(:base, exception.message)
|
78
|
+
invalid_resource!(model)
|
76
79
|
end
|
77
80
|
|
78
81
|
def parameter_missing_error(exception)
|
@@ -139,7 +142,7 @@ module Spree
|
|
139
142
|
end
|
140
143
|
|
141
144
|
def variants_associations
|
142
|
-
[{ option_values: :option_type }, :
|
145
|
+
[{ option_values: :option_type }, :prices, :images]
|
143
146
|
end
|
144
147
|
|
145
148
|
def product_includes
|
@@ -4,13 +4,14 @@ module Spree
|
|
4
4
|
module Api
|
5
5
|
class CustomerReturnsController < Spree::Api::BaseController
|
6
6
|
before_action :load_order
|
7
|
+
before_action :build_customer_return, only: [:create]
|
7
8
|
around_action :lock_order, only: [:create, :update, :destroy, :cancel]
|
8
9
|
|
9
10
|
rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
|
10
11
|
|
11
12
|
def create
|
12
13
|
authorize! :create, CustomerReturn
|
13
|
-
|
14
|
+
|
14
15
|
if @customer_return.save
|
15
16
|
respond_with(@customer_return, status: 201, default_template: :show)
|
16
17
|
else
|
@@ -62,6 +63,34 @@ module Spree
|
|
62
63
|
def customer_return_params
|
63
64
|
params.require(:customer_return).permit(permitted_customer_return_attributes)
|
64
65
|
end
|
66
|
+
|
67
|
+
def build_customer_return
|
68
|
+
customer_return_attributes = customer_return_params
|
69
|
+
return_items_params = customer_return_attributes.
|
70
|
+
delete(:return_items_attributes)
|
71
|
+
|
72
|
+
if return_items_params.is_a? ActionController::Parameters
|
73
|
+
return_items_params = return_items_params.values
|
74
|
+
Spree::Deprecation.warn(
|
75
|
+
"Passing `return_items_attributes` as a hash of hashes is \
|
76
|
+
deprecated and will be removed in future versions of Solidus."
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
@customer_return = CustomerReturn.new(customer_return_attributes)
|
81
|
+
|
82
|
+
@customer_return.return_items = return_items_params.map do |item_params|
|
83
|
+
return_item = if item_params[:id]
|
84
|
+
Spree::ReturnItem.find(item_params[:id])
|
85
|
+
else
|
86
|
+
Spree::ReturnItem.new
|
87
|
+
end
|
88
|
+
|
89
|
+
return_item.assign_attributes(item_params)
|
90
|
+
|
91
|
+
return_item
|
92
|
+
end
|
93
|
+
end
|
65
94
|
end
|
66
95
|
end
|
67
96
|
end
|
@@ -69,7 +69,7 @@ module Spree
|
|
69
69
|
# Products#index does not do the sorting.
|
70
70
|
taxon = Spree::Taxon.find(params[:id])
|
71
71
|
@products = paginate(taxon.products.ransack(params[:q]).result)
|
72
|
-
@products = @products.includes(master: :
|
72
|
+
@products = @products.includes(master: :prices)
|
73
73
|
|
74
74
|
if params[:simple]
|
75
75
|
@exclude_data = {
|
@@ -83,7 +83,7 @@ module Spree
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def include_list
|
86
|
-
[{ option_values: :option_type }, :product, :
|
86
|
+
[{ option_values: :option_type }, :product, :prices, :images, { stock_items: :stock_location }]
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -37,7 +37,16 @@ module Spree
|
|
37
37
|
:variant_property_attributes
|
38
38
|
]
|
39
39
|
|
40
|
-
|
40
|
+
ATTRIBUTES.each do |attribute|
|
41
|
+
define_method attribute do
|
42
|
+
Spree::Api::Config.send(attribute)
|
43
|
+
end
|
44
|
+
|
45
|
+
define_singleton_method attribute do
|
46
|
+
Spree::Deprecation.warn("Please use Spree::Api::Config::#{attribute} instead.")
|
47
|
+
Spree::Api::Config.send(attribute)
|
48
|
+
end
|
49
|
+
end
|
41
50
|
|
42
51
|
def required_fields_for(model)
|
43
52
|
required_fields = model._validators.select do |_field, validations|
|
@@ -51,142 +60,12 @@ module Spree
|
|
51
60
|
required_fields
|
52
61
|
end
|
53
62
|
|
54
|
-
@@product_attributes = [
|
55
|
-
:id, :name, :description, :available_on,
|
56
|
-
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
57
|
-
:taxon_ids, :total_on_hand, :meta_title
|
58
|
-
]
|
59
|
-
|
60
|
-
@@product_property_attributes = [
|
61
|
-
:id, :product_id, :property_id, :value, :property_name
|
62
|
-
]
|
63
|
-
|
64
|
-
@@variant_attributes = [
|
65
|
-
:id, :name, :sku, :weight, :height, :width, :depth, :is_master,
|
66
|
-
:slug, :description, :track_inventory
|
67
|
-
]
|
68
|
-
|
69
|
-
@@variant_property_attributes = [
|
70
|
-
:id, :property_id, :value, :property_name
|
71
|
-
]
|
72
|
-
|
73
|
-
@@image_attributes = [
|
74
|
-
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
75
|
-
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
76
|
-
]
|
77
|
-
|
78
|
-
@@option_value_attributes = [
|
79
|
-
:id, :name, :presentation, :option_type_name, :option_type_id,
|
80
|
-
:option_type_presentation
|
81
|
-
]
|
82
|
-
|
83
|
-
@@order_attributes = [
|
84
|
-
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
85
|
-
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
86
|
-
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
87
|
-
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
88
|
-
:display_additional_tax_total, :tax_total, :currency,
|
89
|
-
:covered_by_store_credit, :display_total_applicable_store_credit,
|
90
|
-
:order_total_after_store_credit, :display_order_total_after_store_credit,
|
91
|
-
:total_applicable_store_credit, :display_total_available_store_credit,
|
92
|
-
:display_store_credit_remaining_after_capture, :canceler_id
|
93
|
-
|
94
|
-
]
|
95
|
-
|
96
|
-
@@line_item_attributes = [:id, :quantity, :price, :variant_id]
|
97
|
-
|
98
|
-
@@option_type_attributes = [:id, :name, :presentation, :position]
|
99
|
-
|
100
|
-
@@payment_attributes = [
|
101
|
-
:id, :source_type, :source_id, :amount, :display_amount,
|
102
|
-
:payment_method_id, :state, :avs_response, :created_at,
|
103
|
-
:updated_at
|
104
|
-
]
|
105
|
-
|
106
|
-
@@payment_method_attributes = [:id, :name, :description]
|
107
|
-
|
108
|
-
@@shipment_attributes = [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :state]
|
109
|
-
|
110
|
-
@@taxonomy_attributes = [:id, :name]
|
111
|
-
|
112
|
-
@@taxon_attributes = [
|
113
|
-
:id, :name, :pretty_name, :permalink, :parent_id,
|
114
|
-
:taxonomy_id
|
115
|
-
]
|
116
|
-
|
117
|
-
@@inventory_unit_attributes = [
|
118
|
-
:id, :state, :variant_id, :shipment_id
|
119
|
-
]
|
120
|
-
|
121
|
-
@@customer_return_attributes = [
|
122
|
-
:id, :number, :stock_location_id, :created_at, :updated_at
|
123
|
-
]
|
124
|
-
|
125
|
-
@@return_authorization_attributes = [
|
126
|
-
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
127
|
-
]
|
128
|
-
|
129
|
-
@@address_attributes = [
|
130
|
-
:id, :name, :address1, :address2, :city, :zipcode, :phone, :company,
|
131
|
-
:alternative_phone, :country_id, :country_iso, :state_id, :state_name,
|
132
|
-
:state_text
|
133
|
-
]
|
134
|
-
|
135
|
-
@@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
136
|
-
|
137
|
-
@@state_attributes = [:id, :name, :abbr, :country_id]
|
138
|
-
|
139
|
-
@@adjustment_attributes = [
|
140
|
-
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
141
|
-
:amount, :label, :promotion_code_id,
|
142
|
-
:finalized, :eligible, :created_at, :updated_at
|
143
|
-
]
|
144
|
-
|
145
|
-
@@creditcard_attributes = [
|
146
|
-
:id, :month, :year, :cc_type, :last_digits, :name
|
147
|
-
]
|
148
|
-
|
149
|
-
@@payment_source_attributes = [
|
150
|
-
:id, :month, :year, :cc_type, :last_digits, :name
|
151
|
-
]
|
152
|
-
|
153
|
-
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
154
|
-
|
155
|
-
@@property_attributes = [:id, :name, :presentation]
|
156
|
-
|
157
|
-
@@stock_location_attributes = [
|
158
|
-
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
159
|
-
:country_id, :zipcode, :phone, :active
|
160
|
-
]
|
161
|
-
|
162
|
-
@@stock_movement_attributes = [:id, :quantity, :stock_item_id]
|
163
|
-
|
164
|
-
@@stock_item_attributes = [
|
165
|
-
:id, :count_on_hand, :backorderable, :stock_location_id,
|
166
|
-
:variant_id
|
167
|
-
]
|
168
|
-
|
169
|
-
@@promotion_attributes = [
|
170
|
-
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
171
|
-
:match_policy, :advertise, :path
|
172
|
-
]
|
173
|
-
|
174
|
-
@@store_attributes = [
|
175
|
-
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
176
|
-
:mail_from_address, :default_currency, :code, :default, :available_locales,
|
177
|
-
:bcc_email
|
178
|
-
]
|
179
|
-
|
180
|
-
@@store_credit_history_attributes = [
|
181
|
-
:display_amount, :display_user_total_amount, :display_action,
|
182
|
-
:display_event_date, :display_remaining_amount
|
183
|
-
]
|
184
|
-
|
185
63
|
def variant_attributes
|
64
|
+
preference_attributes = Spree::Api::Config.variant_attributes
|
186
65
|
if @current_user_roles&.include?("admin")
|
187
|
-
|
66
|
+
preference_attributes + [:cost_price]
|
188
67
|
else
|
189
|
-
|
68
|
+
preference_attributes
|
190
69
|
end
|
191
70
|
end
|
192
71
|
|
@@ -4,8 +4,8 @@
|
|
4
4
|
json.cache! [I18n.locale, @current_user_roles.include?('admin'), current_pricing_options, @product_attributes, @exclude_data, product] do
|
5
5
|
json.(product, *(@product_attributes - [:total_on_hand]))
|
6
6
|
json.total_on_hand(total_on_hand_for(product))
|
7
|
-
json.price(product.
|
8
|
-
json.display_price(product.
|
7
|
+
json.price(product.price_for_options(current_pricing_options)&.amount)
|
8
|
+
json.display_price(product.price_for_options(current_pricing_options)&.money&.to_s)
|
9
9
|
|
10
10
|
@exclude_data ||= {}
|
11
11
|
unless @exclude_data[:variants]
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
json.cache! [I18n.locale, current_pricing_options, variant] do
|
4
4
|
json.(variant, *variant_attributes)
|
5
|
-
json.price(variant.
|
6
|
-
json.display_price(variant.
|
5
|
+
json.price(variant.price_for_options(current_pricing_options)&.amount)
|
6
|
+
json.display_price(variant.price_for_options(current_pricing_options)&.money&.to_s)
|
7
7
|
json.options_text(variant.options_text)
|
8
8
|
json.track_inventory(variant.should_track_inventory?)
|
9
9
|
json.in_stock(variant.in_stock?)
|
data/lib/spree/api/engine.rb
CHANGED
@@ -11,6 +11,10 @@ module Spree
|
|
11
11
|
# Leave initializer empty for backwards-compatibility. Other apps
|
12
12
|
# might still rely on this event.
|
13
13
|
initializer "spree.api.environment", before: :load_config_initializers do; end
|
14
|
+
|
15
|
+
config.after_initialize do
|
16
|
+
Spree::Api::Config.check_load_defaults_called('Spree::Api::Config')
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -3,5 +3,133 @@
|
|
3
3
|
module Spree
|
4
4
|
class ApiConfiguration < Preferences::Configuration
|
5
5
|
preference :requires_authentication, :boolean, default: true
|
6
|
+
|
7
|
+
preference :product_attributes, :array, default: [
|
8
|
+
:id, :name, :description, :available_on,
|
9
|
+
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
10
|
+
:taxon_ids, :total_on_hand, :meta_title
|
11
|
+
]
|
12
|
+
|
13
|
+
preference :product_property_attributes, :array, default: [:id, :product_id, :property_id, :value, :property_name]
|
14
|
+
|
15
|
+
preference :variant_attributes, :array, default: [
|
16
|
+
:id, :name, :sku, :weight, :height, :width, :depth, :is_master,
|
17
|
+
:slug, :description, :track_inventory
|
18
|
+
]
|
19
|
+
|
20
|
+
preference :image_attributes, :array, default: [
|
21
|
+
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
22
|
+
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
23
|
+
]
|
24
|
+
|
25
|
+
preference :option_value_attributes, :array, default: [
|
26
|
+
:id, :name, :presentation, :option_type_name, :option_type_id,
|
27
|
+
:option_type_presentation
|
28
|
+
]
|
29
|
+
|
30
|
+
preference :order_attributes, :array, default: [
|
31
|
+
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
32
|
+
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
33
|
+
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
34
|
+
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
35
|
+
:display_additional_tax_total, :tax_total, :currency,
|
36
|
+
:covered_by_store_credit, :display_total_applicable_store_credit,
|
37
|
+
:order_total_after_store_credit, :display_order_total_after_store_credit,
|
38
|
+
:total_applicable_store_credit, :display_total_available_store_credit,
|
39
|
+
:display_store_credit_remaining_after_capture, :canceler_id
|
40
|
+
]
|
41
|
+
|
42
|
+
preference :line_item_attributes, :array, default: [:id, :quantity, :price, :variant_id]
|
43
|
+
|
44
|
+
preference :option_type_attributes, :array, default: [:id, :name, :presentation, :position]
|
45
|
+
|
46
|
+
preference :payment_attributes, :array, default: [
|
47
|
+
:id, :source_type, :source_id, :amount, :display_amount,
|
48
|
+
:payment_method_id, :state, :avs_response, :created_at,
|
49
|
+
:updated_at
|
50
|
+
]
|
51
|
+
|
52
|
+
preference :payment_method_attributes, :array, default: [:id, :name, :description]
|
53
|
+
|
54
|
+
preference :shipment_attributes, :array, default: [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :state]
|
55
|
+
|
56
|
+
preference :taxonomy_attributes, :array, default: [:id, :name]
|
57
|
+
|
58
|
+
preference :taxon_attributes, :array, default: [
|
59
|
+
:id, :name, :pretty_name, :permalink, :parent_id,
|
60
|
+
:taxonomy_id
|
61
|
+
]
|
62
|
+
|
63
|
+
preference :address_attributes, :array, default: [
|
64
|
+
:id, :name, :address1, :address2, :city, :zipcode, :phone, :company,
|
65
|
+
:alternative_phone, :country_id, :country_iso, :state_id, :state_name,
|
66
|
+
:state_text
|
67
|
+
]
|
68
|
+
|
69
|
+
preference :country_attributes, :array, default: [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
70
|
+
|
71
|
+
preference :state_attributes, :array, default: [:id, :name, :abbr, :country_id]
|
72
|
+
|
73
|
+
preference :adjustment_attributes, :array, default: [
|
74
|
+
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
75
|
+
:amount, :label, :promotion_code_id,
|
76
|
+
:finalized, :eligible, :created_at, :updated_at
|
77
|
+
]
|
78
|
+
|
79
|
+
preference :inventory_unit_attributes, :array, default: [
|
80
|
+
:id, :state, :variant_id, :shipment_id
|
81
|
+
]
|
82
|
+
|
83
|
+
preference :customer_return_attributes, :array, default: [
|
84
|
+
:id, :number, :stock_location_id, :created_at, :updated_at
|
85
|
+
]
|
86
|
+
|
87
|
+
preference :return_authorization_attributes, :array, default: [
|
88
|
+
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
89
|
+
]
|
90
|
+
|
91
|
+
preference :creditcard_attributes, :array, default: [
|
92
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
93
|
+
]
|
94
|
+
|
95
|
+
preference :payment_source_attributes, :array, default: [
|
96
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
97
|
+
]
|
98
|
+
|
99
|
+
preference :user_attributes, :array, default: [:id, :email, :created_at, :updated_at]
|
100
|
+
|
101
|
+
preference :property_attributes, :array, default: [:id, :name, :presentation]
|
102
|
+
|
103
|
+
preference :stock_location_attributes, :array, default: [
|
104
|
+
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
105
|
+
:country_id, :zipcode, :phone, :active
|
106
|
+
]
|
107
|
+
|
108
|
+
preference :stock_movement_attributes, :array, default: [:id, :quantity, :stock_item_id]
|
109
|
+
|
110
|
+
preference :stock_item_attributes, :array, default: [
|
111
|
+
:id, :count_on_hand, :backorderable, :stock_location_id,
|
112
|
+
:variant_id
|
113
|
+
]
|
114
|
+
|
115
|
+
preference :promotion_attributes, :array, default: [
|
116
|
+
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
117
|
+
:match_policy, :advertise, :path
|
118
|
+
]
|
119
|
+
|
120
|
+
preference :store_attributes, :array, default: [
|
121
|
+
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
122
|
+
:mail_from_address, :default_currency, :code, :default, :available_locales,
|
123
|
+
:bcc_email
|
124
|
+
]
|
125
|
+
|
126
|
+
preference :store_credit_history_attributes, :array, default: [
|
127
|
+
:display_amount, :display_user_total_amount, :display_action,
|
128
|
+
:display_event_date, :display_remaining_amount
|
129
|
+
]
|
130
|
+
|
131
|
+
preference :variant_property_attributes, :array, default: [
|
132
|
+
:id, :property_id, :value, :property_name
|
133
|
+
]
|
6
134
|
end
|
7
135
|
end
|