spree_core 4.6.0 → 4.6.2
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 +4 -4
- data/app/models/concerns/spree/translatable_resource_slug.rb +1 -3
- data/app/models/spree/product.rb +16 -0
- data/app/models/spree/taxon.rb +29 -5
- data/app/services/spree/locales/set_fallback_locale_for_store.rb +16 -0
- data/config/initializers/mobility.rb +1 -3
- data/lib/mobility/plugins/store_based_fallbacks.rb +55 -0
- data/lib/spree/core/controller_helpers/locale.rb +7 -0
- data/lib/spree/core/product_duplicator.rb +4 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/testing_support/factories/store_factory.rb +2 -0
- data/lib/spree_core.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25515bda9382eb9a7fc0e07ac95fea0b0094fd7de31af286e0eed57d5feb205f
|
|
4
|
+
data.tar.gz: f7aba240ca2172c68b41e7da1c0e4864fcadb1ec6a632c919cca59fa7e129076
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f829f28024c84e1b8b7dba2868fedeffc0f105b237ef3ad946ad64ec9a2c0f789c8f3ae367f42203a3d3c53be08b598df0a4cd3d58aa45479bf4e755091f27c
|
|
7
|
+
data.tar.gz: afefb4b5952e8187f5dc605202fcc578c13bdd9d7f43d411c0763471c32ddb622aaf6f62c2160b1e835d1f974452d54812ebcabd3a072da0ff31af1a698ab3a8
|
|
@@ -4,12 +4,10 @@ module Spree
|
|
|
4
4
|
|
|
5
5
|
included do
|
|
6
6
|
def localized_slugs_for_store(store)
|
|
7
|
-
localized_slugs = Hash[translations.pluck(:locale, :slug)]
|
|
8
|
-
default_locale = store.default_locale
|
|
9
7
|
supported_locales = store.supported_locales_list
|
|
10
8
|
|
|
11
9
|
supported_locales.each_with_object({}) do |locale, hash|
|
|
12
|
-
hash[locale] =
|
|
10
|
+
hash[locale] = I18n.with_locale(locale) { slug }
|
|
13
11
|
end
|
|
14
12
|
end
|
|
15
13
|
end
|
data/app/models/spree/product.rb
CHANGED
|
@@ -42,9 +42,25 @@ module Spree
|
|
|
42
42
|
translates(*TRANSLATABLE_FIELDS)
|
|
43
43
|
|
|
44
44
|
self::Translation.class_eval do
|
|
45
|
+
before_save :set_slug
|
|
45
46
|
acts_as_paranoid
|
|
46
47
|
# deleted translation values also need to be accessible for index views listing deleted resources
|
|
47
48
|
default_scope { unscope(where: :deleted_at) }
|
|
49
|
+
def set_slug
|
|
50
|
+
self.slug = generate_slug
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def generate_slug
|
|
56
|
+
if name.blank? && slug.blank?
|
|
57
|
+
translated_model.name.to_url
|
|
58
|
+
elsif slug.blank?
|
|
59
|
+
name.to_url
|
|
60
|
+
else
|
|
61
|
+
slug.to_url
|
|
62
|
+
end
|
|
63
|
+
end
|
|
48
64
|
end
|
|
49
65
|
|
|
50
66
|
friendly_id :slug_candidates, use: [:history, :mobility]
|
data/app/models/spree/taxon.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Spree
|
|
|
13
13
|
extend FriendlyId
|
|
14
14
|
friendly_id :permalink, slug_column: :permalink, use: :history
|
|
15
15
|
before_validation :set_permalink, on: :create, if: :name
|
|
16
|
+
alias_attribute :slug, :permalink
|
|
16
17
|
|
|
17
18
|
acts_as_nested_set dependent: :destroy
|
|
18
19
|
|
|
@@ -61,17 +62,40 @@ module Spree
|
|
|
61
62
|
|
|
62
63
|
self::Translation.class_eval do
|
|
63
64
|
alias_attribute :slug, :permalink
|
|
64
|
-
|
|
65
|
-
before_create :set_permalink
|
|
65
|
+
before_save :set_permalink
|
|
66
66
|
|
|
67
67
|
def set_permalink
|
|
68
|
-
|
|
68
|
+
self.permalink = generate_slug
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def generate_slug
|
|
69
74
|
if parent.present?
|
|
70
|
-
|
|
75
|
+
generate_permalink_including_parent
|
|
76
|
+
elsif permalink.blank?
|
|
77
|
+
name_with_fallback.to_url
|
|
71
78
|
else
|
|
72
|
-
|
|
79
|
+
permalink.to_url
|
|
73
80
|
end
|
|
74
81
|
end
|
|
82
|
+
|
|
83
|
+
def generate_permalink_including_parent
|
|
84
|
+
[parent_permalink_with_fallback, (permalink.blank? ? name_with_fallback.to_url : permalink.split('/').last.to_url)].join('/')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def name_with_fallback
|
|
88
|
+
name.blank? ? translated_model.name : name
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def parent
|
|
92
|
+
translated_model.parent
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def parent_permalink_with_fallback
|
|
96
|
+
localized_parent = parent.translations.find_by(locale: locale)
|
|
97
|
+
localized_parent.present? ? localized_parent.permalink : parent.permalink
|
|
98
|
+
end
|
|
75
99
|
end
|
|
76
100
|
|
|
77
101
|
# indicate which filters should be used for a taxon
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Locales
|
|
3
|
+
class SetFallbackLocaleForStore
|
|
4
|
+
def call(store:)
|
|
5
|
+
store_default_locale = store.default_locale
|
|
6
|
+
fallbacks = store.supported_locales_list.each_with_object({}) do |locale, object|
|
|
7
|
+
object[locale] = [store_default_locale]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
fallbacks_instance = I18n::Locale::Fallbacks.new(fallbacks)
|
|
11
|
+
|
|
12
|
+
Mobility.store_based_fallbacks = fallbacks_instance
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'concurrent'
|
|
4
|
+
require 'mobility'
|
|
5
|
+
|
|
6
|
+
# The default implementation in the Mobility gem requires fallbacks to be defined when booting the application.
|
|
7
|
+
# This patch allows to dynamically reconfigure translations fallbacks, by setting Mobility.store_based_fallbacks attribute.
|
|
8
|
+
# The implementation is based on the default fallbacks plugin, with some changes around fetching the list of fallbacks to be used.
|
|
9
|
+
# https://github.com/shioyama/mobility/blob/master/lib/mobility/plugins/fallbacks.rb
|
|
10
|
+
module Mobility
|
|
11
|
+
@store_based_fallbacks = Concurrent::ThreadLocalVar.new(I18n::Locale::Fallbacks.new)
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def store_based_fallbacks
|
|
15
|
+
@store_based_fallbacks.value
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def store_based_fallbacks=(value)
|
|
19
|
+
@store_based_fallbacks.value = value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Plugins
|
|
24
|
+
module StoreBasedFallbacks
|
|
25
|
+
extend ::Mobility::Plugin
|
|
26
|
+
|
|
27
|
+
default true
|
|
28
|
+
requires :backend, include: :before
|
|
29
|
+
|
|
30
|
+
# Applies fallbacks plugin to attributes. Completely disables fallbacks
|
|
31
|
+
# on model if option is +false+.
|
|
32
|
+
included_hook do |_, backend_class|
|
|
33
|
+
unless options[:fallbacks] == false
|
|
34
|
+
backend_class.include(BackendInstanceMethods)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module BackendInstanceMethods
|
|
39
|
+
def read(locale, fallback: true, **kwargs)
|
|
40
|
+
return super(locale, **kwargs) if !fallback || kwargs[:locale]
|
|
41
|
+
|
|
42
|
+
locales = Mobility.store_based_fallbacks[locale]
|
|
43
|
+
locales.each do |fallback_locale|
|
|
44
|
+
value = super(fallback_locale, **kwargs)
|
|
45
|
+
return value if Util.present?(value)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
super(locale, **kwargs)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
register_plugin(:store_based_fallbacks, StoreBasedFallbacks)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -6,6 +6,7 @@ module Spree
|
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
8
|
before_action :set_locale
|
|
9
|
+
before_action :set_fallback_locale
|
|
9
10
|
|
|
10
11
|
if defined?(helper_method)
|
|
11
12
|
helper_method :supported_locales
|
|
@@ -21,6 +22,12 @@ module Spree
|
|
|
21
22
|
I18n.locale = current_locale
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def set_fallback_locale
|
|
26
|
+
return unless respond_to?(:current_store) && current_store.present?
|
|
27
|
+
|
|
28
|
+
Spree::Locales::SetFallbackLocaleForStore.new.call(store: current_store)
|
|
29
|
+
end
|
|
30
|
+
|
|
24
31
|
def current_locale
|
|
25
32
|
@current_locale ||= if user_locale?
|
|
26
33
|
try_spree_current_user.selected_locale
|
|
@@ -26,7 +26,10 @@ module Spree
|
|
|
26
26
|
|
|
27
27
|
def duplicate_product
|
|
28
28
|
product.dup.tap do |new_product|
|
|
29
|
-
|
|
29
|
+
new_product.translations.each do |t|
|
|
30
|
+
t.name = "COPY OF #{t.name}"
|
|
31
|
+
t.slug = nil
|
|
32
|
+
end
|
|
30
33
|
new_product.taxons = product.taxons
|
|
31
34
|
new_product.stores = product.stores
|
|
32
35
|
new_product.created_at = nil
|
data/lib/spree/core/version.rb
CHANGED
|
@@ -13,6 +13,8 @@ FactoryBot.define do
|
|
|
13
13
|
twitter { 'spreecommerce' }
|
|
14
14
|
instagram { 'spreecommerce' }
|
|
15
15
|
meta_description { 'Sample store description.' }
|
|
16
|
+
digital_asset_authorized_clicks { 5 }
|
|
17
|
+
digital_asset_authorized_days { 7 }
|
|
16
18
|
|
|
17
19
|
trait :with_favicon do
|
|
18
20
|
transient do
|
data/lib/spree_core.rb
CHANGED
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.6.
|
|
4
|
+
version: 4.6.2
|
|
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: 2023-
|
|
12
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: actionpack
|
|
@@ -801,6 +801,7 @@ files:
|
|
|
801
801
|
- app/services/spree/line_items/destroy.rb
|
|
802
802
|
- app/services/spree/line_items/helper.rb
|
|
803
803
|
- app/services/spree/line_items/update.rb
|
|
804
|
+
- app/services/spree/locales/set_fallback_locale_for_store.rb
|
|
804
805
|
- app/services/spree/orders/approve.rb
|
|
805
806
|
- app/services/spree/orders/cancel.rb
|
|
806
807
|
- app/services/spree/payments/create.rb
|
|
@@ -923,6 +924,7 @@ files:
|
|
|
923
924
|
- lib/generators/spree/dummy_model/templates/model.rb.tt
|
|
924
925
|
- lib/generators/spree/install/install_generator.rb
|
|
925
926
|
- lib/generators/spree/install/templates/config/initializers/spree.rb
|
|
927
|
+
- lib/mobility/plugins/store_based_fallbacks.rb
|
|
926
928
|
- lib/spree/core.rb
|
|
927
929
|
- lib/spree/core/components.rb
|
|
928
930
|
- lib/spree/core/configuration.rb
|
|
@@ -1077,9 +1079,9 @@ licenses:
|
|
|
1077
1079
|
- BSD-3-Clause
|
|
1078
1080
|
metadata:
|
|
1079
1081
|
bug_tracker_uri: https://github.com/spree/spree/issues
|
|
1080
|
-
changelog_uri: https://github.com/spree/spree/releases/tag/v4.6.
|
|
1082
|
+
changelog_uri: https://github.com/spree/spree/releases/tag/v4.6.2
|
|
1081
1083
|
documentation_uri: https://dev-docs.spreecommerce.org/
|
|
1082
|
-
source_code_uri: https://github.com/spree/spree/tree/v4.6.
|
|
1084
|
+
source_code_uri: https://github.com/spree/spree/tree/v4.6.2
|
|
1083
1085
|
post_install_message:
|
|
1084
1086
|
rdoc_options: []
|
|
1085
1087
|
require_paths:
|