spree_core 4.3.0.rc3 → 4.3.0

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: 9fd663cedb276d7b23b137c9ff65cb153f986deee175e19672198a5ba9078707
4
- data.tar.gz: d9105ced36ac4078df6963e6ca7cd9c2e45bfec3dbed2b2872ff76c99d05dfb3
3
+ metadata.gz: e7b01cdb9b4fae7dbc504ec200b0ac4fad4c3d6f025879bfb8ff1204a39843cf
4
+ data.tar.gz: aef3c6e29b38409ad11305d669b56b5dabae08d0a653783dfab0230ce89bc5c6
5
5
  SHA512:
6
- metadata.gz: db4eb2dfeeca9a7acb56d3146b1e73a97485eec348e9b9537b3145f3ce1c8fc66a7b48d3a68c177fac4cf5d9c93ed7a47738487e034a9698e0eb2f5dba2025de
7
- data.tar.gz: fecab76acd9f180cc9cbe79d23a11f26a2cd86c86ca83e9157b9d8dbe1e475de8d59fea914b75bcab2dc29a4edc1b40074ed056f528abbd96a2750e3088f80df
6
+ metadata.gz: a221ccc5207cd316ff2102787e55f22ff9ade341d0d882ae4a2a2b476c2b62d8fba6463ab71af894b28eb9edc0fa98ee63fac1b03610e419d25d2845568faf77
7
+ data.tar.gz: d1086b0e7216ff453df0197c6a9c7620cee71340cefed09aea7fccbcd2b5be679bb8e0d34656231209bb7dc587ab757594a64809670c898805280ee4a19567bf
@@ -13,7 +13,7 @@ module Spree
13
13
  :products_finder, :taxon_finder, :line_item_by_variant_finder, :cart_estimate_shipping_rates_service,
14
14
  :account_create_address_service, :account_update_address_service, :account_create_service, :account_update_service,
15
15
  :address_finder, :collection_sorter, :error_handler, :current_store_finder, :cart_empty_service, :cart_destroy_service,
16
- :classification_reposition_service, :credit_cards_destroy_service
16
+ :classification_reposition_service, :credit_cards_destroy_service, :cart_associate_service, :cart_change_currency_service
17
17
  ].freeze
18
18
 
19
19
  attr_accessor *INJECTION_POINTS
@@ -43,6 +43,8 @@ module Spree
43
43
  @cart_estimate_shipping_rates_service = 'Spree::Cart::EstimateShippingRates'
44
44
  @cart_empty_service = 'Spree::Cart::Empty'
45
45
  @cart_destroy_service = 'Spree::Cart::Destroy'
46
+ @cart_associate_service = 'Spree::Cart::Associate'
47
+ @cart_change_currency_service = 'Spree::Cart::ChangeCurrency'
46
48
 
47
49
  # checkout
48
50
  @checkout_next_service = 'Spree::Checkout::Next'
@@ -1,6 +1,5 @@
1
1
  module Spree::Cms::Sections
2
2
  class FeaturedArticle < Spree::CmsSection
3
- before_save :reset_link_attributes
4
3
  after_initialize :default_values
5
4
 
6
5
  store :content, accessors: [:title, :subtitle, :button_text, :rte_content], coder: JSON
@@ -14,12 +13,6 @@ module Spree::Cms::Sections
14
13
 
15
14
  private
16
15
 
17
- def reset_link_attributes
18
- if linked_resource_type_changed?
19
- self.linked_resource_id = nil
20
- end
21
- end
22
-
23
16
  def default_values
24
17
  self.gutters ||= 'No Gutters'
25
18
  self.fit ||= 'Screen'
@@ -1,6 +1,5 @@
1
1
  module Spree::Cms::Sections
2
2
  class HeroImage < Spree::CmsSection
3
- before_save :reset_link_attributes
4
3
  after_initialize :default_values
5
4
 
6
5
  store :content, accessors: [:title, :button_text], coder: JSON
@@ -30,14 +29,6 @@ module Spree::Cms::Sections
30
29
 
31
30
  private
32
31
 
33
- def reset_link_attributes
34
- if linked_resource_type_changed?
35
- return if linked_resource_id_was.nil?
36
-
37
- self.linked_resource_id = nil
38
- end
39
- end
40
-
41
32
  def default_values
42
33
  self.gutters ||= 'No Gutters'
43
34
  self.fit ||= 'Screen'
@@ -1,7 +1,7 @@
1
1
  module Spree::Cms::Sections
2
2
  class ImageGallery < Spree::CmsSection
3
3
  after_initialize :default_values
4
- before_save :reset_link_attributes
4
+ validate :reset_multiple_link_attributes
5
5
 
6
6
  LINKED_RESOURCE_TYPE = if Rails::VERSION::STRING < '6.0'
7
7
  ['Spree::Taxon'].freeze
@@ -70,7 +70,7 @@ module Spree::Cms::Sections
70
70
 
71
71
  private
72
72
 
73
- def reset_link_attributes
73
+ def reset_multiple_link_attributes
74
74
  return if Rails::VERSION::STRING < '6.0'
75
75
 
76
76
  if link_type_one_changed?
@@ -1,7 +1,7 @@
1
1
  module Spree::Cms::Sections
2
2
  class SideBySideImages < Spree::CmsSection
3
3
  after_initialize :default_values
4
- before_save :reset_link_attributes
4
+ validate :reset_multiple_link_attributes
5
5
 
6
6
  LINKED_RESOURCE_TYPE = if Rails::VERSION::STRING < '6.0'
7
7
  ['Spree::Taxon'].freeze
@@ -48,7 +48,7 @@ module Spree::Cms::Sections
48
48
 
49
49
  private
50
50
 
51
- def reset_link_attributes
51
+ def reset_multiple_link_attributes
52
52
  return if Rails::VERSION::STRING < '6.0'
53
53
 
54
54
  if link_type_one_changed?
@@ -5,6 +5,8 @@ module Spree
5
5
  acts_as_list scope: :cms_page
6
6
  belongs_to :cms_page, touch: true
7
7
 
8
+ validate :reset_link_attributes
9
+
8
10
  IMAGE_COUNT = ['one', 'two', 'three']
9
11
  IMAGE_TYPES = ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].freeze
10
12
  IMAGE_SIZE = ['sm', 'md', 'lg', 'xl']
@@ -53,5 +55,15 @@ module Spree
53
55
  def fullscreen?
54
56
  fit == 'Screen'
55
57
  end
58
+
59
+ private
60
+
61
+ def reset_link_attributes
62
+ if linked_resource_type_changed?
63
+ return if linked_resource_id_was.nil?
64
+
65
+ self.linked_resource_id = nil
66
+ end
67
+ end
56
68
  end
57
69
  end
@@ -142,17 +142,17 @@ module Spree
142
142
 
143
143
  # Cant use short form block syntax due to https://github.com/Netflix/fast_jsonapi/issues/259
144
144
  def purchasable?
145
- variants_including_master.any?(&:purchasable?)
145
+ default_variant.purchasable? || variants.any?(&:purchasable?)
146
146
  end
147
147
 
148
148
  # Cant use short form block syntax due to https://github.com/Netflix/fast_jsonapi/issues/259
149
149
  def in_stock?
150
- variants_including_master.any?(&:in_stock?)
150
+ default_variant.in_stock? || variants.any?(&:in_stock?)
151
151
  end
152
152
 
153
153
  # Cant use short form block syntax due to https://github.com/Netflix/fast_jsonapi/issues/259
154
154
  def backorderable?
155
- variants_including_master.any?(&:backorderable?)
155
+ default_variant.backorderable? || variants.any?(&:backorderable?)
156
156
  end
157
157
 
158
158
  def find_or_build_master
@@ -301,11 +301,13 @@ module Spree
301
301
  end
302
302
 
303
303
  def total_on_hand
304
- @total_on_hand ||= if any_variants_not_track_inventory?
305
- Float::INFINITY
306
- else
307
- stock_items.sum(:count_on_hand)
308
- end
304
+ @total_on_hand ||= Rails.cache.fetch(['product-total-on-hand', cache_key_with_version]) do
305
+ if any_variants_not_track_inventory?
306
+ Float::INFINITY
307
+ else
308
+ stock_items.sum(:count_on_hand)
309
+ end
310
+ end
309
311
  end
310
312
 
311
313
  # Master variant may be deleted (i.e. when the product is deleted)
@@ -2,6 +2,7 @@ module Spree
2
2
  class StockLocation < Spree::Base
3
3
  has_many :shipments
4
4
  has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
5
+ has_many :variants, through: :stock_items
5
6
  has_many :stock_movements, through: :stock_items
6
7
 
7
8
  belongs_to :state, class_name: 'Spree::State', optional: true
@@ -14,6 +15,7 @@ module Spree
14
15
 
15
16
  after_create :create_stock_items, if: :propagate_all_variants?
16
17
  after_save :ensure_one_default
18
+ after_update :conditional_touch_records
17
19
 
18
20
  def state_text
19
21
  state.try(:abbr) || state.try(:name) || state_name
@@ -134,5 +136,12 @@ module Spree
134
136
  StockLocation.where(default: true).where.not(id: id).update_all(default: false)
135
137
  end
136
138
  end
139
+
140
+ def conditional_touch_records
141
+ return unless active_changed?
142
+
143
+ stock_items.update_all(updated_at: Time.current)
144
+ variants.update_all(updated_at: Time.current)
145
+ end
137
146
  end
138
147
  end
@@ -44,6 +44,7 @@ module Spree
44
44
  scope :for_store, ->(store) { joins(:taxonomy).where(spree_taxonomies: { store_id: store.id }) }
45
45
 
46
46
  self.whitelisted_ransackable_associations = %w[taxonomy]
47
+ self.whitelisted_ransackable_attributes = %w[name permalink]
47
48
 
48
49
  scope :for_stores, ->(stores) { joins(:taxonomy).where(spree_taxonomies: { store_id: stores.ids }) }
49
50
 
@@ -60,7 +60,7 @@ module Spree
60
60
 
61
61
  after_touch :clear_in_stock_cache
62
62
 
63
- scope :in_stock, -> { joins(:stock_items).where('count_on_hand > ? OR track_inventory = ?', 0, false) }
63
+ scope :in_stock, -> { joins(:stock_items).where("#{Spree::StockItem.table_name}.count_on_hand > ? OR #{Spree::Variant.table_name}.track_inventory = ?", 0, false) }
64
64
  scope :backorderable, -> { joins(:stock_items).where(spree_stock_items: { backorderable: true }) }
65
65
  scope :in_stock_or_backorderable, -> { in_stock.or(backorderable) }
66
66
 
@@ -256,7 +256,13 @@ module Spree
256
256
  end
257
257
  end
258
258
 
259
- delegate :total_on_hand, :can_supply?, :backorderable?, to: :quantifier
259
+ def backorderable?
260
+ @backorderable ||= Rails.cache.fetch(['variant-backorderable', cache_key_with_version]) do
261
+ quantifier.backorderable?
262
+ end
263
+ end
264
+
265
+ delegate :total_on_hand, :can_supply?, to: :quantifier
260
266
 
261
267
  alias is_backorderable? backorderable?
262
268
 
@@ -291,7 +297,7 @@ module Spree
291
297
  end
292
298
 
293
299
  def backordered?
294
- @backordered ||= total_on_hand <= 0 && stock_items.exists?(backorderable: true)
300
+ @backordered ||= !in_stock? && stock_items.exists?(backorderable: true)
295
301
  end
296
302
 
297
303
  private
@@ -3,6 +3,26 @@ module Spree
3
3
  class OptionsPresenter
4
4
  FilterableOptionType = Struct.new(:option_type, :option_values, keyword_init: true) do
5
5
  delegate_missing_to :option_type
6
+
7
+ def to_h
8
+ {
9
+ id: option_type.id,
10
+ name: option_type.name,
11
+ presentation: option_type.presentation,
12
+ option_values: option_values.map { |e| option_value_hash(e) }
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def option_value_hash(option_value)
19
+ {
20
+ id: option_value.id,
21
+ name: option_value.name,
22
+ presentation: option_value.presentation,
23
+ position: option_value.position
24
+ }
25
+ end
6
26
  end
7
27
 
8
28
  def initialize(option_values_scope:)
@@ -14,9 +14,29 @@ module Spree
14
14
  property.uniq_values(product_properties_scope: product_properties)
15
15
  end
16
16
 
17
+ def to_h
18
+ {
19
+ id: property.id,
20
+ name: property.name,
21
+ presentation: property.presentation,
22
+ values: values_hash
23
+ }
24
+ end
25
+
17
26
  private
18
27
 
19
28
  attr_reader :property
29
+
30
+ def values_hash
31
+ value_hashes = uniq_values.map do |filter_param, value|
32
+ {
33
+ value: value,
34
+ filter_param: filter_param
35
+ }
36
+ end
37
+
38
+ value_hashes.sort_by { |e| e[:value] }
39
+ end
20
40
  end
21
41
  end
22
42
  end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module Cart
3
+ class Associate
4
+ prepend Spree::ServiceModule::Base
5
+
6
+ def call(guest_order:, user:)
7
+ if guest_order.user.nil?
8
+ guest_order.associate_user!(user)
9
+ success(guest_order)
10
+ else
11
+ failure(guest_order, 'Already assigned to a user')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module Cart
3
+ class ChangeCurrency
4
+ prepend Spree::ServiceModule::Base
5
+
6
+ def call(order:, new_currency:)
7
+ return failure('Currency not supported') unless supported_currency?(order, new_currency)
8
+
9
+ result = order.update!(currency: new_currency) rescue false
10
+
11
+ if result
12
+ success(order)
13
+ else
14
+ failure('Failed to update order')
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def supported_currency?(order, currency)
21
+ store = order.store
22
+ supported_currencies = store.supported_currencies_list
23
+ supported_currencies.map(&:iso_code).include?(currency.upcase)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -31,8 +31,14 @@ module Spree
31
31
  def by_sku(scope)
32
32
  return scope unless (value = sort_by?('sku'))
33
33
 
34
+ select_product_attributes = if scope.to_sql.include?("#{Spree::Product.table_name}.*")
35
+ ''
36
+ else
37
+ "#{Spree::Product.table_name}.*, "
38
+ end
39
+
34
40
  scope.joins(:master).
35
- select("#{Spree::Product.table_name}.*, #{Spree::Variant.table_name}.sku").
41
+ select("#{select_product_attributes}#{Spree::Variant.table_name}.sku").
36
42
  where(Spree::Variant.table_name.to_s => { is_master: true }).
37
43
  order("#{Spree::Variant.table_name}.sku #{value[1]}")
38
44
  end
@@ -564,6 +564,7 @@ en:
564
564
  draft_mode: Draft Mode
565
565
  full_width: Full width
566
566
  link_to_taxon: Link to Taxon
567
+ link_to_product: Link to Product
567
568
  title: Title
568
569
  fit: Fit To
569
570
  info_hero_image_body: "<p>The Hero Image section adds a large image with a button and tagline text to your page.</p>
@@ -1349,6 +1350,7 @@ en:
1349
1350
  backordered_confirm_info: Selected item is backordered so expect delays. Are you sure you want to order it?
1350
1351
  overview: Overview
1351
1352
  package_from: package from
1353
+ page: Page
1352
1354
  page_not_found: Sorry! Page you are looking can’t be found.
1353
1355
  pagination:
1354
1356
  next_page: next page &raquo;
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- VERSION = '4.3.0.rc3'.freeze
2
+ VERSION = '4.3.0'.freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0.rc3
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-30 00:00:00.000000000 Z
12
+ date: 2021-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -699,6 +699,8 @@ files:
699
699
  - app/services/spree/account/update.rb
700
700
  - app/services/spree/build_localized_redirect_url.rb
701
701
  - app/services/spree/cart/add_item.rb
702
+ - app/services/spree/cart/associate.rb
703
+ - app/services/spree/cart/change_currency.rb
702
704
  - app/services/spree/cart/create.rb
703
705
  - app/services/spree/cart/destroy.rb
704
706
  - app/services/spree/cart/empty.rb
@@ -724,7 +726,6 @@ files:
724
726
  - app/sorters/spree/products/sort.rb
725
727
  - app/validators/db_maximum_length_validator.rb
726
728
  - app/validators/email_validator.rb
727
- - app/views/spree/shared/_purchased_items_table.text.erb
728
729
  - config/initializers/active_storage.rb
729
730
  - config/initializers/friendly_id.rb
730
731
  - config/initializers/inflections.rb
@@ -1194,9 +1195,9 @@ licenses:
1194
1195
  - BSD-3-Clause
1195
1196
  metadata:
1196
1197
  bug_tracker_uri: https://github.com/spree/spree/issues
1197
- changelog_uri: https://github.com/spree/spree/releases/tag/v4.3.0.rc3
1198
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.3.0
1198
1199
  documentation_uri: https://dev-docs.spreecommerce.org/
1199
- source_code_uri: https://github.com/spree/spree/tree/v4.3.0.rc3
1200
+ source_code_uri: https://github.com/spree/spree/tree/v4.3.0
1200
1201
  post_install_message:
1201
1202
  rdoc_options: []
1202
1203
  require_paths:
@@ -1212,7 +1213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1212
1213
  - !ruby/object:Gem::Version
1213
1214
  version: 1.8.23
1214
1215
  requirements: []
1215
- rubygems_version: 3.2.3
1216
+ rubygems_version: 3.1.4
1216
1217
  signing_key:
1217
1218
  specification_version: 4
1218
1219
  summary: The bare bones necessary for Spree
@@ -1,25 +0,0 @@
1
- <% line_items.each do |item| %>
2
- <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) <%= Spree.t('at_symbol') %> <%= item.single_money %> = <%= item.display_amount %>
3
- <% end %>
4
- ============================================================
5
- <%= Spree.t('order_mailer.subtotal') %> <%= order.display_item_total %>
6
- <% if order.line_item_adjustments.exists? %>
7
- <% if order.all_adjustments.promotion.eligible.exists? %>
8
- <% order.all_adjustments.promotion.eligible.group_by(&:label).each do |label, adjustments| %>
9
- <%= Spree.t(:promotion) %>: <%= label %> <%= Spree::Money.new(adjustments.sum(&:amount), currency: order.currency) %>
10
- <% end %>
11
- <% end %>
12
- <% end %>
13
-
14
- <% order.shipments.group_by { |s| s.selected_shipping_rate.try(:name) }.each do |name, shipments| %>
15
- <%= Spree.t(:shipping) %>: <%= name %> <%= Spree::Money.new(shipments.sum(&:discounted_cost), currency: order.currency) %>
16
- <% end %>
17
-
18
- <% if order.additional_tax_total != 0 %>
19
- <%= Spree.t(:tax) %>: <%= order.display_additional_tax_total.to_html %>
20
- <% end %>
21
-
22
- <% order.adjustments.eligible.each do |adjustment| %>
23
- <% next if (adjustment.source_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
24
- <%= adjustment.label %> <%= adjustment.display_amount %>
25
- <% end %>