spree_core 4.3.0.rc2 → 4.3.0.rc3

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: d280751e897448ce4593ebe1d5f2fc9cd823e998699864ac8b52d2dfa28b49d6
4
- data.tar.gz: 21ed38407942b369d6a7a2360730190a124264bd9b8137e79c49d4058fac16f6
3
+ metadata.gz: 9fd663cedb276d7b23b137c9ff65cb153f986deee175e19672198a5ba9078707
4
+ data.tar.gz: d9105ced36ac4078df6963e6ca7cd9c2e45bfec3dbed2b2872ff76c99d05dfb3
5
5
  SHA512:
6
- metadata.gz: 803917626fa68a87c54fd9d88dbb2388e84fefce8873ef3a7a96e7a49e1a1a7a9b327864a7c222fc31006795eaefbf10c12db584e5cd308b19464617b3235b80
7
- data.tar.gz: f1ecb88f76d6061727b9bd569f24ae672491507248584106d1be936a2dfb3c78a1a1693b0affb84d0f8e34fe2991346b2884386ac7ac67df838408a81d10bc85
6
+ metadata.gz: db4eb2dfeeca9a7acb56d3146b1e73a97485eec348e9b9537b3145f3ce1c8fc66a7b48d3a68c177fac4cf5d9c93ed7a47738487e034a9698e0eb2f5dba2025de
7
+ data.tar.gz: fecab76acd9f180cc9cbe79d23a11f26a2cd86c86ca83e9157b9d8dbe1e475de8d59fea914b75bcab2dc29a4edc1b40074ed056f528abbd96a2750e3088f80df
@@ -3,16 +3,18 @@ module Spree
3
3
  class Find
4
4
  def initialize(scope:, params:)
5
5
  @scope = scope
6
- @ids = String(params.dig(:filter, :ids)).split(',')
7
- @parent = params.dig(:filter, :parent_id)
8
- @taxonomy = params.dig(:filter, :taxonomy_id)
9
- @name = params.dig(:filter, :name)
10
- @roots = params.dig(:filter, :roots)
6
+ @ids = String(params.dig(:filter, :ids)).split(',')
7
+ @parent = params.dig(:filter, :parent_id)
8
+ @parent_permalink = params.dig(:filter, :parent_permalink)
9
+ @taxonomy = params.dig(:filter, :taxonomy_id)
10
+ @name = params.dig(:filter, :name)
11
+ @roots = params.dig(:filter, :roots)
11
12
  end
12
13
 
13
14
  def execute
14
15
  taxons = by_ids(scope)
15
16
  taxons = by_parent(taxons)
17
+ taxons = by_parent_permalink(taxons)
16
18
  taxons = by_taxonomy(taxons)
17
19
  taxons = by_roots(taxons)
18
20
  taxons = by_name(taxons)
@@ -22,7 +24,7 @@ module Spree
22
24
 
23
25
  private
24
26
 
25
- attr_reader :ids, :parent, :taxonomy, :roots, :name, :scope
27
+ attr_reader :ids, :parent, :parent_permalink, :taxonomy, :roots, :name, :scope
26
28
 
27
29
  def ids?
28
30
  ids.present?
@@ -32,6 +34,10 @@ module Spree
32
34
  parent.present?
33
35
  end
34
36
 
37
+ def parent_permalink?
38
+ parent_permalink.present?
39
+ end
40
+
35
41
  def taxonomy?
36
42
  taxonomy.present?
37
43
  end
@@ -60,6 +66,16 @@ module Spree
60
66
  taxons.where(parent_id: parent)
61
67
  end
62
68
 
69
+ def by_parent_permalink(taxons)
70
+ return taxons unless parent_permalink?
71
+
72
+ if Rails::VERSION::STRING >= '6.1'
73
+ taxons.joins(:parent).where(parent: { permalink: parent_permalink })
74
+ else
75
+ taxons.joins("INNER JOIN #{Spree::Taxon.table_name} AS parent_taxon ON parent_taxon.id = #{Spree::Taxon.table_name}.parent_id").where(["parent_taxon.permalink = ?", parent_permalink])
76
+ end
77
+ end
78
+
63
79
  def by_taxonomy(taxons)
64
80
  return taxons unless taxonomy?
65
81
 
@@ -246,11 +246,13 @@ module Spree
246
246
  options = options.first || {}
247
247
  options[:alt] ||= product.name
248
248
  image_path = default_image_for_product_or_variant(product)
249
- if image_path.present?
250
- create_product_image_tag image_path, product, options, style
251
- else
252
- image_tag "noimage/#{style}.png", options
253
- end
249
+ img = if image_path.present?
250
+ create_product_image_tag image_path, product, options, style
251
+ else
252
+ inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%"
253
+ end
254
+
255
+ content_tag(:div, img, class: "admin-product-image-container #{style}-img")
254
256
  end
255
257
  end
256
258
 
@@ -0,0 +1,24 @@
1
+ module Spree
2
+ module ImageMethods
3
+ extend ActiveSupport::Concern
4
+
5
+ def generate_url(size:, gravity: 'center', quality: 80, background: 'show')
6
+ return if size.blank?
7
+ size = size.gsub(/\s+/, '')
8
+
9
+ return unless size.match(/(\d+)x(\d+)/)
10
+
11
+ polymorphic_path(attachment.variant(
12
+ gravity: gravity,
13
+ resize: size,
14
+ extent: size,
15
+ background: background,
16
+ quality: quality.to_i
17
+ ), only_path: true)
18
+ end
19
+
20
+ def original_url
21
+ polymorphic_path(attachment, only_path: true)
22
+ end
23
+ end
24
+ end
@@ -9,14 +9,12 @@ module Spree
9
9
 
10
10
  attr_accessor :test
11
11
 
12
+ preference :dummy_key, :string, default: 'PUBLICKEY123'
13
+
12
14
  def provider_class
13
15
  self.class
14
16
  end
15
17
 
16
- def preferences
17
- {}
18
- end
19
-
20
18
  def create_profile(payment)
21
19
  return if payment.source.has_payment_profile?
22
20
 
@@ -88,5 +86,9 @@ module Spree
88
86
  end
89
87
  random
90
88
  end
89
+
90
+ def public_preference_keys
91
+ [:dummy_key]
92
+ end
91
93
  end
92
94
  end
@@ -2,6 +2,7 @@ module Spree
2
2
  class Image < Asset
3
3
  include Configuration::ActiveStorage
4
4
  include Rails.application.routes.url_helpers
5
+ include ::Spree::ImageMethods
5
6
 
6
7
  # In Rails 5.x class constants are being undefined/redefined during the code reloading process
7
8
  # in a rails development environment, after which the actual ruby objects stored in those class constants
@@ -15,13 +16,8 @@ module Spree
15
16
  width, height = size.chop.split('x')
16
17
 
17
18
  {
18
- url: polymorphic_path(attachment.variant(
19
- gravity: 'center',
20
- resize: size,
21
- extent: size,
22
- background: 'snow2',
23
- quality: 80
24
- ), only_path: true),
19
+ url: generate_url(size: size),
20
+ size: size,
25
21
  width: width,
26
22
  height: height
27
23
  }
@@ -35,13 +31,7 @@ module Spree
35
31
  width, height = size.chop.split('x')
36
32
 
37
33
  {
38
- url: polymorphic_path(attachment.variant(
39
- gravity: 'center',
40
- resize: size,
41
- extent: size,
42
- background: 'snow2',
43
- quality: 80
44
- ), only_path: true),
34
+ url: generate_url(size: size),
45
35
  size: size,
46
36
  width: width,
47
37
  height: height
@@ -59,16 +49,7 @@ module Spree
59
49
  end
60
50
 
61
51
  def plp_url
62
- size = self.class.styles[:plp_and_carousel]
63
- variant = attachment.variant(
64
- gravity: 'center',
65
- resize: size,
66
- extent: size,
67
- background: 'snow2',
68
- quality: 80
69
- )
70
-
71
- polymorphic_path(variant, only_path: true)
52
+ generate_url(size: self.class.styles[:plp_and_carousel])
72
53
  end
73
54
  end
74
55
  end
@@ -87,5 +87,17 @@ module Spree
87
87
 
88
88
  store_ids.include?(store.id)
89
89
  end
90
+
91
+ def public_preferences
92
+ public_preference_keys.each_with_object({}) do |key, hash|
93
+ hash[key] = preferences[key]
94
+ end
95
+ end
96
+
97
+ protected
98
+
99
+ def public_preference_keys
100
+ []
101
+ end
90
102
  end
91
103
  end
@@ -2,6 +2,7 @@ module Spree
2
2
  class TaxonImage < Asset
3
3
  include Configuration::ActiveStorage
4
4
  include Rails.application.routes.url_helpers
5
+ include ::Spree::ImageMethods
5
6
 
6
7
  def styles
7
8
  self.class.styles.map do |_, size|
@@ -2,34 +2,46 @@ module Spree
2
2
  class BaseSorter
3
3
  def initialize(scope, params = {}, allowed_sort_attributes = [])
4
4
  @scope = scope
5
- @sort = params[:sort]
6
5
  @allowed_sort_attributes = allowed_sort_attributes
6
+ @sort = sort_fields(params[:sort])
7
7
  end
8
8
 
9
9
  def call
10
- by_param_attribute(scope)
10
+ by_param_attributes(scope)
11
11
  end
12
12
 
13
13
  protected
14
14
 
15
15
  attr_reader :scope, :collection, :sort, :allowed_sort_attributes
16
16
 
17
- def by_param_attribute(scope)
18
- return scope if sort_field.blank? || !allowed_sort_attributes.include?(sort_field.to_sym)
17
+ def by_param_attributes(scope)
18
+ return scope if sort.empty?
19
19
 
20
- scope.order("#{sort_field}": order_direction)
20
+ sort.each do |value, order|
21
+ next if value.blank? || allowed_sort_attributes.exclude?(value.to_sym)
22
+
23
+ scope = scope.order("#{value}": order)
24
+ end
25
+
26
+ scope
27
+ end
28
+
29
+ def sort_fields(sort)
30
+ return [] if sort.nil?
31
+
32
+ sort.split(',').map { |field| [sort_field(field), order_direction(field)] }
21
33
  end
22
34
 
23
- def desc_order
24
- @desc_order ||= String(sort)[0] == '-'
35
+ def desc_order(field)
36
+ String(field)[0] == '-'
25
37
  end
26
38
 
27
- def sort_field
28
- @sort_field ||= desc_order ? sort[1..-1] : sort
39
+ def sort_field(field)
40
+ desc_order(field) ? field[1..-1] : field
29
41
  end
30
42
 
31
- def order_direction
32
- desc_order ? :desc : :asc
43
+ def order_direction(field)
44
+ desc_order(field) ? :desc : :asc
33
45
  end
34
46
  end
35
47
  end
@@ -7,8 +7,9 @@ module Spree
7
7
  end
8
8
 
9
9
  def call
10
- products = by_param_attribute(scope)
10
+ products = by_param_attributes(scope)
11
11
  products = by_price(products)
12
+ products = by_sku(products)
12
13
 
13
14
  products.distinct
14
15
  end
@@ -17,18 +18,27 @@ module Spree
17
18
 
18
19
  attr_reader :sort, :scope, :currency, :allowed_sort_attributes
19
20
 
20
- def price?
21
- sort_field == 'price'
22
- end
23
-
24
21
  def by_price(scope)
25
- return scope unless price?
22
+ return scope unless (value = sort_by?('price'))
26
23
 
27
24
  scope.joins(master: :prices).
28
25
  select("#{Spree::Product.table_name}.*, #{Spree::Price.table_name}.amount").
29
26
  distinct.
30
27
  where(spree_prices: { currency: currency }).
31
- order("#{Spree::Price.table_name}.amount #{order_direction}")
28
+ order("#{Spree::Price.table_name}.amount #{value[1]}")
29
+ end
30
+
31
+ def by_sku(scope)
32
+ return scope unless (value = sort_by?('sku'))
33
+
34
+ scope.joins(:master).
35
+ select("#{Spree::Product.table_name}.*, #{Spree::Variant.table_name}.sku").
36
+ where(Spree::Variant.table_name.to_s => { is_master: true }).
37
+ order("#{Spree::Variant.table_name}.sku #{value[1]}")
38
+ end
39
+
40
+ def sort_by?(field)
41
+ sort.detect { |s| s[0] == field }
32
42
  end
33
43
  end
34
44
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- VERSION = '4.3.0.rc2'.freeze
2
+ VERSION = '4.3.0.rc3'.freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -8,6 +8,8 @@ module Spree
8
8
  :image_attributes,
9
9
  :inventory_unit_attributes,
10
10
  :line_item_attributes,
11
+ :menu_attributes,
12
+ :menu_item_attributes,
11
13
  :option_type_attributes,
12
14
  :option_value_attributes,
13
15
  :payment_attributes,
@@ -62,6 +64,11 @@ module Spree
62
64
 
63
65
  @@line_item_attributes = [:id, :variant_id, :quantity]
64
66
 
67
+ @@menu_attributes = [:name, :locale, :location]
68
+
69
+ @@menu_item_attributes = [:name, :subtite, :destination, :new_window, :item_type,
70
+ :linked_resource_type, :linked_resource_id, :code, :menu_id]
71
+
65
72
  @@option_type_attributes = [:name, :presentation, :option_values_attributes]
66
73
 
67
74
  @@option_value_attributes = [:name, :presentation]
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.rc2
4
+ version: 4.3.0.rc3
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-23 00:00:00.000000000 Z
12
+ date: 2021-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -472,6 +472,7 @@ files:
472
472
  - app/models/concerns/spree/display_link.rb
473
473
  - app/models/concerns/spree/display_money.rb
474
474
  - app/models/concerns/spree/filter_param.rb
475
+ - app/models/concerns/spree/image_methods.rb
475
476
  - app/models/concerns/spree/memoized_data.rb
476
477
  - app/models/concerns/spree/multi_store_resource.rb
477
478
  - app/models/concerns/spree/named_type.rb
@@ -1193,9 +1194,9 @@ licenses:
1193
1194
  - BSD-3-Clause
1194
1195
  metadata:
1195
1196
  bug_tracker_uri: https://github.com/spree/spree/issues
1196
- changelog_uri: https://github.com/spree/spree/releases/tag/v4.3.0.rc2
1197
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.3.0.rc3
1197
1198
  documentation_uri: https://dev-docs.spreecommerce.org/
1198
- source_code_uri: https://github.com/spree/spree/tree/v4.3.0.rc2
1199
+ source_code_uri: https://github.com/spree/spree/tree/v4.3.0.rc3
1199
1200
  post_install_message:
1200
1201
  rdoc_options: []
1201
1202
  require_paths: