solidus_api 4.8.0 → 4.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4ff5000b131bd3d2fce8bc9e81165d860447f4c5a94d5364852af656fa4de8d
4
- data.tar.gz: b46b662948606c65253e766a0b207ea00ad473aa217811b70a0d4bdee2c69c8a
3
+ metadata.gz: d263182b8d9ee2d2072f32c87022a1e0883b1522b898db8dadab534674cf70ce
4
+ data.tar.gz: 9c4036c14c41532ff348e3a444e8c720c589914ad3641f0e9f5132c21792c925
5
5
  SHA512:
6
- metadata.gz: 8519bddff6d7f9b5dc478d19a1ef09b7f68473a89f94ab044c5c45e462bf93e72986888f2a6e5bc2dd0075f43d41330da07e0e9ba6955f751720f24a61fffbed
7
- data.tar.gz: d0ee7c6a4d2584a00bbeb88e8442c3d6985e1c6f66590007458744cd3f11a2a9bbe9a06b88eddcba449dd7cf0d8fa239e513380ae9df3466fffb0726c8391ca1
6
+ metadata.gz: 5ee813760d0c3f5f2c1c15b276587ab109e8897b80ac71f014b064a5eb02628e07fbcab21c674539fd668d0b5e864d06eaf6e1600278978ec6565724ba99d869
7
+ data.tar.gz: 357c9e20c2accc9a98b78b408d440063b82fc2787f887061188981eb3fd788224cebdf3c76da59aa986f56b2894d9298833989c16252ac2aba3f3fa19098d8b6
@@ -15,7 +15,7 @@ module Spree
15
15
  authorize! :update, @order, order_token
16
16
  find_address
17
17
 
18
- success = @order.update({"#{@order_source}_attributes" => address_params})
18
+ success = @order.contents.update_cart({"#{@order_source}_attributes" => address_params})
19
19
  @address = @order.send(@order_source)
20
20
 
21
21
  if success
@@ -121,6 +121,7 @@ module Spree
121
121
  if params[:order]
122
122
  normalize_params
123
123
  prevent_customer_metadata_update
124
+ prevent_line_item_variant_update
124
125
  params.require(:order).permit(permitted_order_attributes)
125
126
  else
126
127
  {}
@@ -133,6 +134,16 @@ module Spree
133
134
  params[:order]&.delete(:customer_metadata)
134
135
  end
135
136
 
137
+ def prevent_line_item_variant_update
138
+ line_items_attributes = params[:order][:line_items_attributes]
139
+ return unless line_items_attributes
140
+
141
+ line_items_attributes = line_items_attributes.values unless line_items_attributes.is_a?(Array)
142
+ line_items_attributes.each do |line_item_attributes|
143
+ line_item_attributes.delete(:variant_id) if line_item_attributes[:id].present?
144
+ end
145
+ end
146
+
136
147
  def normalize_params
137
148
  if params[:order][:payments]
138
149
  payments_params = params[:order].delete(:payments)
@@ -15,8 +15,7 @@ module Spree
15
15
 
16
16
  @products = @products.includes(products_includes)
17
17
  @products = paginate(@products.distinct)
18
- expires_in 15.minutes, public: true
19
- headers["Surrogate-Control"] = "max-age=#{15.minutes}"
18
+ set_cache_headers
20
19
  respond_with(@products)
21
20
  end
22
21
 
@@ -25,9 +24,7 @@ module Spree
25
24
 
26
25
  def show
27
26
  @product = find_product(params[:id])
28
- expires_in 15.minutes, public: true
29
- headers["Surrogate-Control"] = "max-age=#{15.minutes}"
30
- headers["Surrogate-Key"] = "product_id=1"
27
+ set_cache_headers(surrogate_key: "product_id=#{@product.id}")
31
28
  respond_with(@product)
32
29
  end
33
30
 
@@ -115,6 +112,14 @@ module Spree
115
112
 
116
113
  def variants_includes = {stock_items: :stock_location, images: Spree::Image.attachment_preloads}
117
114
 
115
+ def set_cache_headers(surrogate_key: nil)
116
+ return if current_api_user
117
+
118
+ expires_in 15.minutes, public: true
119
+ headers["Surrogate-Control"] = "max-age=#{15.minutes}"
120
+ headers["Surrogate-Key"] = surrogate_key if surrogate_key
121
+ end
122
+
118
123
  def product_params
119
124
  product_params = params.require(:product).permit(permitted_product_attributes)
120
125
  if product_params[:taxon_ids].present?
@@ -99,7 +99,10 @@ module Spree
99
99
  end
100
100
 
101
101
  def transfer_to_shipment
102
- @desired_shipment ||= Spree::Shipment.find_by!(number: params[:target_shipment_number])
102
+ unless @desired_shipment
103
+ @desired_shipment = @original_shipment.order.shipments.find_by!(number: params[:target_shipment_number])
104
+ authorize! :update, @desired_shipment
105
+ end
103
106
 
104
107
  fulfilment_changer = Spree::FulfilmentChanger.new(
105
108
  current_shipment: @original_shipment,
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, line_item] do
3
+ json.cache! [I18n.locale, line_item, line_item_attributes, variant_attributes] do
4
4
  json.call(line_item, *line_item_attributes)
5
5
  json.single_display_amount(line_item.single_display_amount.to_s)
6
6
  json.display_amount(line_item.display_amount.to_s)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, order] do
3
+ json.cache! [I18n.locale, order, order_attributes] do
4
4
  json.call(order, *order_attributes)
5
5
  json.display_item_total(order.display_item_total.to_s)
6
6
  json.total_quantity(order.line_items.to_a.sum(&:quantity))
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, shipment] do
3
+ json.cache! [I18n.locale, shipment, shipment_attributes, line_item_attributes, order_attributes, variant_attributes] do
4
4
  json.call(shipment, *shipment_attributes)
5
5
  json.partial!("spree/api/shipments/small", shipment:)
6
6
  json.inventory_units(shipment.inventory_units) do |inventory_unit|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, shipment] do
3
+ json.cache! [I18n.locale, shipment, shipment_attributes] do
4
4
  json.call(shipment, *shipment_attributes)
5
5
  json.order_id(shipment.order.number)
6
6
  json.stock_location_name(shipment.stock_location.name)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, @shipment] do
3
+ json.cache! [I18n.locale, @shipment, shipment_attributes, variant_attributes] do
4
4
  json.call(@shipment, *shipment_attributes)
5
5
  json.order_id(@shipment.order.number)
6
6
  json.stock_location_name(@shipment.stock_location.name)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant] do
3
+ json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant, variant_attributes] do
4
4
  json.call(variant, *variant_attributes)
5
5
  json.partial!("spree/api/variants/small", variant:)
6
6
  json.variant_properties(variant.variant_properties) do |variant_property|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, current_pricing_options, variant] do
3
+ json.cache! [I18n.locale, current_pricing_options, variant, variant_attributes] do
4
4
  json.call(variant, *variant_attributes)
5
5
  json.price(variant.price_for_options(current_pricing_options)&.amount)
6
6
  json.display_price(variant.price_for_options(current_pricing_options)&.money&.to_s)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 4.8.0
60
+ version: 4.8.1
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
- version: 4.8.0
67
+ version: 4.8.1
68
68
  description: REST API for the Solidus e-commerce framework.
69
69
  email: contact@solidus.io
70
70
  executables: []
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  - !ruby/object:Gem::Version
273
273
  version: 1.8.23
274
274
  requirements: []
275
- rubygems_version: 4.0.20
275
+ rubygems_version: 4.0.10
276
276
  specification_version: 4
277
277
  summary: REST API for the Solidus e-commerce framework.
278
278
  test_files: []