solidus_api 3.0.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3349d2f9f1e2ee840300b0b9d450532aebd18e3a43046c417730d652685a12b6
4
- data.tar.gz: 971d33f767037782bbee55b58cb82d87763f13f160c5176743310d85ae5a3fa9
3
+ metadata.gz: 8cc031580e5c012f20d223ecdfa34ed52ab06fd0f726a35cbaefc07dd30182b3
4
+ data.tar.gz: 750ebaf332da5ff2a33bd5238d5a4d057ad054f58521637a894fd2c78a24fb78
5
5
  SHA512:
6
- metadata.gz: 195addc223059a83072248fe3070db331be82f097c0071b71a8c24fb4fd7d38f58a22dc9ff85fc2046fe1ac65c82155381f1d6d5eae34481a67c023c0cbd1dbf
7
- data.tar.gz: 8334024dd036e0ec738ede892acf1ffc9e14e9faf7e982641fa6e362bb3d4d6d41b490d129b2dceb3bcb3cefdbdf283dc7daf47925ee2caff72d52f93e7e16a5
6
+ metadata.gz: 0e438f87dd7c2524eacd973a3127a6e8c92249c13a2b4a18483c8034cb916552201cc9cba587e9a192375267f1fc7360f01169e1038b21c5cc9388ea03a0d790
7
+ data.tar.gz: 8f67f7e5363d0830424ccb0e2186ebaa2e87eb05cdb699eaf4f5f0859302d4a4f3a6ac2e64aeea3657ad20784fc761cc593eb1b42a2e564dcd1e3b4484ae8b9f
@@ -71,8 +71,11 @@ module Spree
71
71
  end
72
72
 
73
73
  def gateway_error(exception)
74
- @order.errors.add(:base, exception.message)
75
- invalid_resource!(@order)
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 }, :default_price, :images]
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
- @customer_return = CustomerReturn.create(customer_return_params)
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
@@ -186,7 +186,7 @@ module Spree
186
186
  },
187
187
  variant: {
188
188
  product: {},
189
- default_price: {},
189
+ prices: {},
190
190
  option_values: {
191
191
  option_type: {}
192
192
  }
@@ -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: :default_price)
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, :default_price, :images, { stock_items: :stock_location }]
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
- mattr_reader(*ATTRIBUTES)
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
- @@variant_attributes + [:cost_price]
66
+ preference_attributes + [:cost_price]
188
67
  else
189
- @@variant_attributes
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.price_for(current_pricing_options).try(:to_d))
8
- json.display_price(product.price_for(current_pricing_options).to_s)
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.price_for(current_pricing_options).try(:to_d))
6
- json.display_price(variant.price_for(current_pricing_options).to_s)
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?)
@@ -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
data/openapi/main.hub.yml CHANGED
@@ -38,11 +38,11 @@ pages:
38
38
  path: /authentication
39
39
  data:
40
40
  $ref: ./authentication.md
41
- - title: Pagination
41
+ - title: Pagination and Filtering
42
42
  route:
43
- path: /pagination
43
+ path: /pagination-and-filtering
44
44
  data:
45
- $ref: ./pagination.md
45
+ $ref: ./pagination-and-filtering.md
46
46
  - title: Errors
47
47
  route:
48
48
  path: /errors
@@ -0,0 +1,23 @@
1
+ # Pagination and Filtering
2
+
3
+ ## Pagination
4
+
5
+ Most endpoints that return a collection are paginated. A paginated response contains metadata about the current page at the root level and the resources in the current page in a child key named after the resource (e.g. `orders`).
6
+
7
+ You can pass the `page` and `per_page` parameters to set the current page and the desired number of items per page. Note that the default and the maximum number of items per page is decided at the application level.
8
+
9
+ All pagination metadata is documented in the individual API endpoints, so take a look there if you're unsure what data you can expect.
10
+
11
+ ## Filtering
12
+
13
+ Most endpoints that return a collection also have the ability to filter data using query params. This works taking advantage of the search filters provided by [Ransack](https://github.com/activerecord-hackery/ransack/).
14
+
15
+ For example, if we want to retrieve only products that contain the word "Watch" in their title we can make the following request:
16
+
17
+ ```
18
+ GET /products?q[name_cont]=Watch
19
+ ```
20
+
21
+ The `name_cont` matcher will generate a query using `LIKE` to retrieve all the products that contain the value specified. For an extensive list of search matchers supported, please refer to the Ransack documentation.
22
+
23
+ The result will be paginated as described in the paragraph above.