spree_core 4.1.5 → 4.1.6

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: 1643c4f1dedde056b96b0c1e6c312c452084a0d34bc2d5ed2abc648d2185f43a
4
- data.tar.gz: cbc7c195925ef217208fa373120ebbd8cef241815dadedd24972bcd9cf904eb4
3
+ metadata.gz: 96827f4cde98df9373667a89b28276d3ffc954bf7e2c25fb33d1675012c518ef
4
+ data.tar.gz: c84bd003851d88dae731ac73e31041a9fd0a523357c3b48476686935cdf7b070
5
5
  SHA512:
6
- metadata.gz: 337338d05ac9009476f2e66e099abc21f13461b1db2e02e85a571d722de625f6bcc38fd1009ae8a78bef10ff19aee2e687438da5415a5888125e930ee6865c21
7
- data.tar.gz: 92275d9db7cecb217bc2922898e9e1ce0359eac14606e11686ed339b5173826a2cd85329adc9c3a4bd713740e9f419f9e2909bef4024280c947bf301ce3d8a35
6
+ metadata.gz: d8aba081fef39e67d547ca039dcf20477d10388a9c382e8f368b4be2ed0e86496f96b86b557f400bdcece01a86f29c09868f7176442875bd6fc79ea2843c729d
7
+ data.tar.gz: 565ba5fe5695eada6e6b0e530ae318be22b1105200d8138595a17b39eef1ed4e0d4e1a8ccdd65e7b4b6ac349394bad2a78e18eee932ed5bbc19284e49b562f48
@@ -99,7 +99,7 @@ module Spree
99
99
  def by_taxons(products)
100
100
  return products unless taxons?
101
101
 
102
- products.joins(:taxons).where(spree_taxons: { id: taxons })
102
+ products.joins(:classifications).where(Classification.table_name => { taxon_id: taxons })
103
103
  end
104
104
 
105
105
  def by_name(products)
@@ -142,13 +142,25 @@ module Spree
142
142
 
143
143
  case sort_by
144
144
  when 'default'
145
- products
145
+ if taxons?
146
+ products.
147
+ select("#{Product.table_name}.*, #{Classification.table_name}.position").
148
+ order("#{Classification.table_name}.position" => :asc)
149
+ else
150
+ products
151
+ end
146
152
  when 'newest-first'
147
153
  products.order(available_on: :desc)
148
154
  when 'price-high-to-low'
149
- products.select('spree_products.*, spree_prices.amount').reorder('').send(:descend_by_master_price)
155
+ products.
156
+ select("#{Product.table_name}.*, #{Spree::Price.table_name}.amount").
157
+ reorder('').
158
+ send(:descend_by_master_price)
150
159
  when 'price-low-to-high'
151
- products.select('spree_products.*, spree_prices.amount').reorder('').send(:ascend_by_master_price)
160
+ products.
161
+ select("#{Product.table_name}.*, #{Spree::Price.table_name}.amount").
162
+ reorder('').
163
+ send(:ascend_by_master_price)
152
164
  end
153
165
  end
154
166
 
@@ -160,10 +172,11 @@ module Spree
160
172
  discontinued ? products : products.available
161
173
  end
162
174
 
163
- def taxon_ids(taxon_id)
164
- return unless (taxon = Spree::Taxon.find_by(id: taxon_id))
175
+ def taxon_ids(taxons_ids)
176
+ return if taxons_ids.nil? || taxons_ids.to_s.blank?
165
177
 
166
- taxon.self_and_descendants.ids.map(&:to_s)
178
+ taxons = Spree::Taxon.where(id: taxons_ids.to_s.split(','))
179
+ taxons.map(&:cached_self_and_descendants_ids).flatten.compact.uniq.map(&:to_s)
167
180
  end
168
181
  end
169
182
  end
@@ -67,7 +67,7 @@ module Spree
67
67
  cache_key_elements = common_product_cache_keys
68
68
  cache_key_elements += [
69
69
  product.cache_key_with_version,
70
- product.possible_promotions
70
+ product.possible_promotions.map(&:cache_key)
71
71
  ]
72
72
 
73
73
  cache_key_elements.compact.join('/')
@@ -79,8 +79,9 @@ module Spree
79
79
  string.slice(0..449) + '...'
80
80
  end
81
81
 
82
- def available_status(product) # will return a human readable string
83
- return Spree.t(:discontinued) if product.discontinued?
82
+ # will return a human readable string
83
+ def available_status(product)
84
+ return Spree.t(:discontinued) if product.discontinued?
84
85
  return Spree.t(:deleted) if product.deleted?
85
86
 
86
87
  if product.available?
@@ -116,16 +117,16 @@ module Spree
116
117
  def related_products
117
118
  return [] unless @product.respond_to?(:has_related_products?) && @product.has_related_products?(:related_products)
118
119
 
119
- @_related_products ||= @product.
120
- related_products.
121
- includes(
122
- :tax_category,
123
- master: [
124
- :prices,
125
- images: { attachment_attachment: :blob },
126
- ]
127
- ).
128
- limit(Spree::Config[:products_per_page])
120
+ @related_products ||= @product.
121
+ related_products.
122
+ includes(
123
+ :tax_category,
124
+ master: [
125
+ :prices,
126
+ images: { attachment_attachment: :blob },
127
+ ]
128
+ ).
129
+ limit(Spree::Config[:products_per_page])
129
130
  end
130
131
 
131
132
  def product_available_in_currency?
@@ -145,7 +146,7 @@ module Spree
145
146
  end
146
147
 
147
148
  def variants_option_types_presenter(variants, product)
148
- @_variants_option_types_presenter ||= begin
149
+ @variants_option_types_presenter ||= begin
149
150
  option_types = Spree::Variants::OptionTypesFinder.new(variant_ids: variants.map(&:id)).execute
150
151
 
151
152
  Spree::Variants::OptionTypesPresenter.new(option_types, variants, product)
@@ -81,7 +81,7 @@ module Spree
81
81
  # SELECT COUNT(*) ...
82
82
  add_search_scope :in_taxon do |taxon|
83
83
  includes(:classifications).
84
- where('spree_products_taxons.taxon_id' => taxon.self_and_descendants.pluck(:id)).
84
+ where('spree_products_taxons.taxon_id' => taxon.cached_self_and_descendants_ids).
85
85
  order('spree_products_taxons.position ASC')
86
86
  end
87
87
 
@@ -221,7 +221,7 @@ module Spree
221
221
 
222
222
  # specifically avoid having an order for taxon search (conflicts with main order)
223
223
  def self.prepare_taxon_conditions(taxons)
224
- ids = taxons.map { |taxon| taxon.self_and_descendants.pluck(:id) }.flatten.uniq
224
+ ids = taxons.map(&:cached_self_and_descendants_ids).flatten.uniq
225
225
  joins(:classifications).where(Classification.table_name => { taxon_id: ids })
226
226
  end
227
227
  private_class_method :prepare_taxon_conditions
@@ -111,7 +111,7 @@ module Spree
111
111
 
112
112
  alias options product_option_types
113
113
 
114
- self.whitelisted_ransackable_associations = %w[stores variants_including_master master variants]
114
+ self.whitelisted_ransackable_associations = %w[taxons stores variants_including_master master variants]
115
115
  self.whitelisted_ransackable_attributes = %w[description name slug discontinue_on]
116
116
  self.whitelisted_ransackable_scopes = %w[not_discontinued]
117
117
 
@@ -341,7 +341,7 @@ module Spree
341
341
  price: master.price
342
342
  )
343
343
  end
344
- throw(:abort) unless save
344
+ save
345
345
  end
346
346
 
347
347
  def ensure_master
@@ -23,7 +23,7 @@ module Spree
23
23
  order = line_item.order
24
24
 
25
25
  # Prevent negative order totals
26
- amounts << order.amount - order.adjustments.sum(:amount).abs if order.adjustments.any?
26
+ amounts << order.amount - order.adjustments.eligible.sum(:amount).abs if order.adjustments.eligible.any?
27
27
 
28
28
  amounts.min * -1
29
29
  end
@@ -74,6 +74,12 @@ module Spree
74
74
  ancestor_chain + name.to_s
75
75
  end
76
76
 
77
+ def cached_self_and_descendants_ids
78
+ Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do
79
+ self_and_descendants.ids
80
+ end
81
+ end
82
+
77
83
  # awesome_nested_set sorts by :lft and :rgt. This call re-inserts the child
78
84
  # node so that its resulting position matches the observable 0-indexed position.
79
85
  # ** Note ** no :position column needed - a_n_s doesn't handle the reordering if
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '4.1.5'
3
+ '4.1.6'
4
4
  end
5
5
  end
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  s.add_dependency 'state_machines-activerecord', '~> 0.6'
40
40
  s.add_dependency 'state_machines-activemodel', '~> 0.7'
41
41
  s.add_dependency 'stringex'
42
- s.add_dependency 'twitter_cldr', '>= 4.3', '< 6.0'
42
+ s.add_dependency 'twitter_cldr', '>= 4.3', '< 7.0'
43
43
  s.add_dependency 'sprockets', '~> 3.7'
44
44
  s.add_dependency 'sprockets-rails'
45
45
  s.add_dependency 'mini_magick', '>= 4.9.4', '< 4.11.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
4
+ version: 4.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -309,7 +309,7 @@ dependencies:
309
309
  version: '4.3'
310
310
  - - "<"
311
311
  - !ruby/object:Gem::Version
312
- version: '6.0'
312
+ version: '7.0'
313
313
  type: :runtime
314
314
  prerelease: false
315
315
  version_requirements: !ruby/object:Gem::Requirement
@@ -319,7 +319,7 @@ dependencies:
319
319
  version: '4.3'
320
320
  - - "<"
321
321
  - !ruby/object:Gem::Version
322
- version: '6.0'
322
+ version: '7.0'
323
323
  - !ruby/object:Gem::Dependency
324
324
  name: sprockets
325
325
  requirement: !ruby/object:Gem::Requirement