spree_core 4.7.3 → 4.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/app/finders/spree/taxons/find.rb +7 -3
  4. data/app/models/concerns/spree/product_scopes.rb +19 -19
  5. data/app/models/concerns/spree/user_address.rb +4 -2
  6. data/app/models/spree/address.rb +1 -20
  7. data/app/models/spree/asset.rb +1 -1
  8. data/app/models/spree/cms_page.rb +1 -1
  9. data/app/models/spree/country.rb +0 -26
  10. data/app/models/spree/credit_card.rb +4 -2
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/digital.rb +1 -1
  13. data/app/models/spree/digital_link.rb +1 -1
  14. data/app/models/spree/inventory_unit.rb +1 -1
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/menu.rb +1 -1
  17. data/app/models/spree/menu_item.rb +1 -1
  18. data/app/models/spree/option_type.rb +3 -3
  19. data/app/models/spree/option_value.rb +3 -3
  20. data/app/models/spree/order.rb +5 -3
  21. data/app/models/spree/payment.rb +1 -1
  22. data/app/models/spree/payment_capture_event.rb +1 -1
  23. data/app/models/spree/price.rb +3 -1
  24. data/app/models/spree/product.rb +24 -13
  25. data/app/models/spree/product_property.rb +4 -2
  26. data/app/models/spree/promotion.rb +1 -1
  27. data/app/models/spree/property.rb +6 -4
  28. data/app/models/spree/prototype.rb +1 -1
  29. data/app/models/spree/refund.rb +1 -1
  30. data/app/models/spree/reimbursement.rb +1 -1
  31. data/app/models/spree/return_authorization.rb +1 -1
  32. data/app/models/spree/return_item.rb +1 -1
  33. data/app/models/spree/shipment.rb +1 -1
  34. data/app/models/spree/shipping_category.rb +1 -1
  35. data/app/models/spree/shipping_method.rb +1 -1
  36. data/app/models/spree/stock_item.rb +2 -2
  37. data/app/models/spree/stock_location.rb +6 -1
  38. data/app/models/spree/stock_movement.rb +1 -1
  39. data/app/models/spree/stock_transfer.rb +1 -1
  40. data/app/models/spree/store.rb +2 -4
  41. data/app/models/spree/store_credit.rb +1 -1
  42. data/app/models/spree/store_favicon_image.rb +11 -2
  43. data/app/models/spree/tax_category.rb +1 -1
  44. data/app/models/spree/tax_rate.rb +1 -1
  45. data/app/models/spree/taxon.rb +20 -4
  46. data/app/models/spree/taxonomy.rb +3 -3
  47. data/app/models/spree/variant.rb +9 -4
  48. data/app/models/spree/wished_item.rb +1 -1
  49. data/app/models/spree/wishlist.rb +1 -1
  50. data/app/models/spree/zone.rb +1 -1
  51. data/app/services/spree/addresses/update.rb +1 -0
  52. data/app/services/spree/seeds/all.rb +15 -13
  53. data/app/services/spree/seeds/stores.rb +2 -2
  54. data/app/sorters/spree/products/sort.rb +1 -1
  55. data/config/initializers/mobility.rb +1 -0
  56. data/config/locales/en.yml +2 -36
  57. data/config/routes.rb +7 -8
  58. data/db/migrate/20210929090344_create_stock_item_stock_location_id_variant_id_coalesce_deleted_at_unique_index.rb +1 -28
  59. data/db/migrate/20230103144439_create_option_type_translations.rb +0 -1
  60. data/db/migrate/20230103151034_create_option_value_translations.rb +0 -1
  61. data/db/migrate/20230109084253_create_product_property_translations.rb +0 -1
  62. data/db/migrate/20230109105943_create_property_translations.rb +0 -2
  63. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +2 -8
  64. data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +35 -0
  65. data/db/migrate/20240514105216_add_weight_and_dimension_units_to_spree_variants.rb +6 -0
  66. data/lib/generators/spree/custom_authentication/custom_authentication_generator.rb +23 -0
  67. data/lib/generators/spree/{custom_user → custom_authentication}/templates/authentication_helpers.rb.tt +1 -14
  68. data/lib/generators/spree/custom_user/custom_user_generator.rb +3 -8
  69. data/lib/generators/spree/custom_user/templates/current_user_helpers.rb.tt +15 -0
  70. data/lib/generators/spree/custom_user/templates/migration.rb.tt +2 -2
  71. data/lib/generators/spree/dummy/dummy_generator.rb +1 -6
  72. data/lib/generators/spree/dummy/templates/rails/database.yml +19 -21
  73. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  74. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -0
  75. data/lib/spree/core/configuration.rb +11 -25
  76. data/lib/spree/core/controller_helpers/locale.rb +5 -1
  77. data/lib/spree/core/engine.rb +4 -1
  78. data/lib/spree/core/preferences/runtime_configuration.rb +43 -0
  79. data/lib/spree/core/product_duplicator.rb +2 -0
  80. data/lib/spree/core/product_filters.rb +9 -2
  81. data/lib/spree/core/runtime_configuration.rb +9 -0
  82. data/lib/spree/core/version.rb +1 -1
  83. data/lib/spree/core/webhooks.rb +13 -0
  84. data/lib/spree/core.rb +10 -1
  85. data/lib/spree/money.rb +38 -5
  86. data/lib/spree/testing_support/authorization_helpers.rb +3 -1
  87. data/lib/spree/testing_support/common_rake.rb +7 -18
  88. data/spree_core.gemspec +7 -7
  89. metadata +47 -50
  90. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +0 -5
  91. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +0 -5
  92. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +0 -66
  93. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +0 -58
  94. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +0 -59
  95. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +0 -82
  96. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +0 -5
  97. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +0 -11
  98. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +0 -11
  99. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96a1ab3dd325e2cd0053b0ad881b73ddb153624fd04dba62dd61d4e01ab2aca4
4
- data.tar.gz: 1e947a1bba157dd1df4ba6773d869675da4bffa856f4f1c57f63a4c7b5a592aa
3
+ metadata.gz: a07adab86367df355f16ba975b123b0c203579de5882cec741c8f81e1dfff5f0
4
+ data.tar.gz: b7c41de3fb4ab564ca7c7ebbe0642e2ed6d0235ea59c4661ceb524435bf51c3f
5
5
  SHA512:
6
- metadata.gz: 6307ed6baf1241414853b53c6528f08448fb465fcdd4603e96f29aaf507fa2188a7f481f4e000b5ec9370e7894c49680ad86ad61d39b1c2e36d7735988c36c95
7
- data.tar.gz: 1d75cd60145ae2fe99f9d9a8e2c13cd7c3b9026847b561c31299ce1bbd0596c7f4e14499e01f658dfe0e8c87e5335ee718d6983213d8ac1d8338a3300836d1f3
6
+ metadata.gz: eb9917a0b380bc500b7bcfa63f0a36dcdefb6afc1237b52bd95cd8365d3caba3af00d97eed799834a6db6aa1689d043a27107dc53045a24ccaa7f702152470dd
7
+ data.tar.gz: 22c9f866d4e5a5ce0f556fa8dd38bbb59a9a6d6c7f64d7a9de300c30ccf4f63625e75ea2f119eb65e25a03bcf35925905ff522e163925919b048e304e331519f
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2015, Spree Commerce, Inc. and other contributors
1
+ Copyright (c) 2007-2024, Spree Commerce, Inc., Spark Solutuons Sp. z o.o. and other contributors
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
@@ -65,9 +65,13 @@ module Spree
65
65
  def by_parent_permalink(taxons)
66
66
  return taxons unless parent_permalink?
67
67
 
68
- taxons.joins(:parent).
69
- join_translation_table(Taxon, 'parents_spree_taxons').
70
- where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])
68
+ if Spree.use_translations?
69
+ taxons.joins(:parent).
70
+ join_translation_table(Taxon, 'parents_spree_taxons').
71
+ where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])
72
+ else
73
+ taxons.joins(:parent).where(parent: { permalink: parent_permalink })
74
+ end
71
75
  end
72
76
 
73
77
  def by_taxonomy(taxons)
@@ -33,15 +33,15 @@ module Spree
33
33
 
34
34
  def self.property_conditions(property)
35
35
  properties_table = Property.table_name
36
- property_translations_table = Property.translation_table_alias
36
+
37
37
  case property
38
38
  when Property then { "#{properties_table}.id" => property.id }
39
39
  when Integer then { "#{properties_table}.id" => property }
40
40
  else
41
41
  if Property.column_for_attribute('id').type == :uuid
42
- ["#{property_translations_table.name} = ? OR #{properties_table.id} = ?", property, property]
42
+ ["#{properties_table}.name = ? OR #{properties_table}.id = ?", property, property]
43
43
  else
44
- { "#{property_translations_table}.name" => property }
44
+ { "#{properties_table}.name" => property }
45
45
  end
46
46
  end
47
47
  end
@@ -127,25 +127,29 @@ module Spree
127
127
 
128
128
  # a scope that finds all products having property specified by name, object or id
129
129
  add_search_scope :with_property do |property|
130
- joins(:properties).join_translation_table(Property).where(property_conditions(property))
130
+ joins(:properties).where(property_conditions(property))
131
131
  end
132
132
 
133
133
  # a simple test for product with a certain property-value pairing
134
134
  # note that it can test for properties with NULL values, but not for absent values
135
135
  add_search_scope :with_property_value do |property, value|
136
- joins(:properties).
137
- join_translation_table(Property).
138
- join_translation_table(ProductProperty).
139
- where("#{ProductProperty.translation_table_alias}.value = ?", value).
140
- where(property_conditions(property))
136
+ if Spree.use_translations?
137
+ joins(:properties).
138
+ join_translation_table(Property).
139
+ join_translation_table(ProductProperty).
140
+ where("#{ProductProperty.translation_table_alias}.value = ?", value).
141
+ where(property_conditions(property))
142
+ else
143
+ joins(:properties).
144
+ where("#{ProductProperty.table_name}.value = ?", value).
145
+ where(property_conditions(property))
146
+ end
141
147
  end
142
148
 
143
149
  add_search_scope :with_property_values do |property_filter_param, property_values|
144
150
  joins(product_properties: :property).
145
- join_translation_table(Property).
146
- join_translation_table(ProductProperty).
147
- where(Property.translation_table_alias => { filter_param: property_filter_param }).
148
- where(ProductProperty.translation_table_alias => { filter_param: property_values.map(&:parameterize) })
151
+ where(Property.table_name => { filter_param: property_filter_param }).
152
+ where(ProductProperty.table_name => { filter_param: property_values.map(&:parameterize) })
149
153
  end
150
154
 
151
155
  add_search_scope :with_option do |option|
@@ -156,9 +160,7 @@ module Spree
156
160
  elsif OptionType.column_for_attribute('id').type == :uuid
157
161
  joins(:option_types).where(spree_option_types: { name: option }).or(Product.joins(:option_types).where(spree_option_types: { id: option }))
158
162
  else
159
- joins(:option_types).
160
- join_translation_table(OptionType).
161
- where(OptionType.translation_table_alias => { name: option })
163
+ joins(:option_types).where(OptionType.table_name => { name: option })
162
164
  end
163
165
  end
164
166
 
@@ -179,9 +181,7 @@ module Spree
179
181
 
180
182
  group("#{Spree::Product.table_name}.id").
181
183
  joins(variants_including_master: :option_values).
182
- join_translation_table(Spree::OptionValue).
183
- where(Spree::OptionValue.translation_table_alias => { name: value },
184
- Spree::OptionValue.table_name => { option_type_id: option_type_id })
184
+ where(Spree::OptionValue.table_name => { name: value, option_type_id: option_type_id })
185
185
  end
186
186
 
187
187
  # Finds all products which have either:
@@ -5,11 +5,13 @@ module Spree
5
5
  included do
6
6
  belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address',
7
7
  optional: true
8
- alias_attribute :billing_address, :bill_address
8
+ alias_method :billing_address, :bill_address
9
+ alias_method :billing_address=, :bill_address=
9
10
 
10
11
  belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address',
11
12
  optional: true
12
- alias_attribute :shipping_address, :ship_address
13
+ alias_method :shipping_address, :ship_address
14
+ alias_method :shipping_address=, :ship_address=
13
15
 
14
16
  accepts_nested_attributes_for :ship_address, :bill_address
15
17
 
@@ -3,7 +3,7 @@ module Spree
3
3
  require 'validates_zipcode'
4
4
 
5
5
  include Spree::Metadata
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
  if defined?(Spree::Security::Addresses)
@@ -68,25 +68,6 @@ module Spree
68
68
  self.whitelisted_ransackable_attributes = ADDRESS_FIELDS
69
69
  self.whitelisted_ransackable_associations = %w[country state user]
70
70
 
71
- def self.build_default
72
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
73
- `Address#build_default` is deprecated and will be removed in Spree 5.0.
74
- Please use standard rails `Address.new(country: current_store.default_country)`
75
- DEPRECATION
76
- new(country: Spree::Country.default)
77
- end
78
-
79
- def self.default(user = nil, kind = 'bill')
80
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
81
- `Address#default` is deprecated and will be removed in Spree 5.0.
82
- DEPRECATION
83
- if user && user_address = user.public_send(:"#{kind}_address")
84
- user_address.clone
85
- else
86
- build_default
87
- end
88
- end
89
-
90
71
  def self.required_fields
91
72
  Spree::Address.validators.map do |v|
92
73
  v.is_a?(ActiveModel::Validations::PresenceValidator) ? v.attributes : []
@@ -2,7 +2,7 @@ module Spree
2
2
  class Asset < Spree::Base
3
3
  include Support::ActiveStorage
4
4
  include Spree::Metadata
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
 
@@ -3,7 +3,7 @@ module Spree
3
3
  include Spree::SingleStoreResource
4
4
  include Spree::DisplayLink
5
5
 
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
 
@@ -1,9 +1,5 @@
1
1
  module Spree
2
2
  class Country < Spree::Base
3
- # we need to have this callback before any dependent: :destroy associations
4
- # https://github.com/rails/rails/issues/3458
5
- # before_destroy :ensure_not_default
6
-
7
3
  has_many :addresses, dependent: :restrict_with_error
8
4
  has_many :states,
9
5
  -> { order name: :asc },
@@ -18,17 +14,6 @@ module Spree
18
14
 
19
15
  validates :name, :iso_name, :iso, :iso3, presence: true, uniqueness: { case_sensitive: false, scope: spree_base_uniqueness_scope }
20
16
 
21
- def self.default(store = nil)
22
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
23
- `Country#default` is deprecated and will be removed in Spree 5.0.
24
- Please use `current_store.default_country` instead
25
- DEPRECATION
26
- store ||= Spree::Store.default
27
- country_id = store.default_country_id
28
- default = find_by(id: country_id) if country_id.present?
29
- default || find_by(iso: 'US') || first
30
- end
31
-
32
17
  def self.by_iso(iso)
33
18
  where(['LOWER(iso) = ?', iso.downcase]).or(where(['LOWER(iso3) = ?', iso.downcase])).take
34
19
  end
@@ -45,16 +30,5 @@ module Spree
45
30
  def to_s
46
31
  name
47
32
  end
48
-
49
- private
50
-
51
- def ensure_not_default
52
- Spree::Deprecation.warn('Country#ensure_not_default is deprecated and will be removed in Spree v5')
53
-
54
- if id.eql?(Spree::Config[:default_country_id])
55
- errors.add(:base, Spree.t(:default_country_cannot_be_deleted))
56
- throw(:abort)
57
- end
58
- end
59
33
  end
60
34
  end
@@ -2,7 +2,7 @@ module Spree
2
2
  class CreditCard < Spree::Base
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
4
  include Spree::Metadata
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
  if defined?(Spree::Security::CreditCards)
@@ -99,13 +99,15 @@ module Spree
99
99
  def cc_type=(type)
100
100
  self[:cc_type] = case type
101
101
  when 'mastercard', 'maestro' then 'master'
102
- when 'amex' then 'american_express'
102
+ when 'amex' then 'american_express'
103
103
  when 'dinersclub' then 'diners_club'
104
104
  when '' then try_type_from_number
105
105
  else type
106
106
  end
107
107
  end
108
108
 
109
+ alias_method :brand=, :cc_type=
110
+
109
111
  def verification_value=(value)
110
112
  @verification_value = value.to_s.gsub(/\s/, '')
111
113
  end
@@ -3,7 +3,7 @@ module Spree
3
3
  include Spree::Core::NumberGenerator.new(prefix: 'CR', length: 9)
4
4
  include Spree::NumberIdentifier
5
5
  include Spree::Metadata
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
 
@@ -3,7 +3,7 @@ module Spree
3
3
  belongs_to :variant
4
4
  has_many :digital_links, dependent: :destroy
5
5
 
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
 
@@ -6,7 +6,7 @@ module Spree
6
6
  has_secure_token
7
7
  end
8
8
 
9
- if defined?(Spree::Webhooks)
9
+ if defined?(Spree::Webhooks::HasWebhooks)
10
10
  include Spree::Webhooks::HasWebhooks
11
11
  end
12
12
  if defined?(Spree::Security::DigitalLinks)
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class InventoryUnit < Spree::Base
3
- if defined?(Spree::Webhooks)
3
+ if defined?(Spree::Webhooks::HasWebhooks)
4
4
  include Spree::Webhooks::HasWebhooks
5
5
  end
6
6
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class LineItem < Spree::Base
3
3
  include Spree::Metadata
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Menu < Spree::Base
3
3
  include Spree::SingleStoreResource
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class MenuItem < Spree::Base
3
3
  include Spree::DisplayLink
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -3,12 +3,12 @@ module Spree
3
3
  include Spree::UniqueName
4
4
  include Spree::Metadata
5
5
  include Spree::TranslatableResource
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
 
10
- TRANSLATABLE_FIELDS = %i[name presentation].freeze
11
- translates(*TRANSLATABLE_FIELDS)
10
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
11
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
12
12
 
13
13
  acts_as_list
14
14
  auto_strip_attributes :name, :presentation
@@ -2,12 +2,12 @@ module Spree
2
2
  class OptionValue < Spree::Base
3
3
  include Spree::Metadata
4
4
  include Spree::TranslatableResource
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
 
9
- TRANSLATABLE_FIELDS = %i[name presentation].freeze
10
- translates(*TRANSLATABLE_FIELDS)
9
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
10
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
11
11
 
12
12
  belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
13
13
 
@@ -25,7 +25,7 @@ module Spree
25
25
  include Spree::SingleStoreResource
26
26
  include Spree::MemoizedData
27
27
  include Spree::Metadata
28
- if defined?(Spree::Webhooks)
28
+ if defined?(Spree::Webhooks::HasWebhooks)
29
29
  include Spree::Webhooks::HasWebhooks
30
30
  end
31
31
  if defined?(Spree::Security::Orders)
@@ -102,11 +102,13 @@ module Spree
102
102
 
103
103
  belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address',
104
104
  optional: true, dependent: :destroy
105
- alias_attribute :billing_address, :bill_address
105
+ alias_method :billing_address, :bill_address
106
+ alias_method :billing_address=, :bill_address=
106
107
 
107
108
  belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address',
108
109
  optional: true, dependent: :destroy
109
- alias_attribute :shipping_address, :ship_address
110
+ alias_method :shipping_address, :ship_address
111
+ alias_method :shipping_address=, :ship_address=
110
112
 
111
113
  belongs_to :store, class_name: 'Spree::Store'
112
114
 
@@ -6,7 +6,7 @@ module Spree
6
6
  include Spree::NumberIdentifier
7
7
  include Spree::NumberAsParam
8
8
  include Spree::Metadata
9
- if defined?(Spree::Webhooks)
9
+ if defined?(Spree::Webhooks::HasWebhooks)
10
10
  include Spree::Webhooks::HasWebhooks
11
11
  end
12
12
  if defined?(Spree::Security::Payments)
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class PaymentCaptureEvent < Spree::Base
3
- if defined?(Spree::Webhooks)
3
+ if defined?(Spree::Webhooks::HasWebhooks)
4
4
  include Spree::Webhooks::HasWebhooks
5
5
  end
6
6
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Price < Spree::Base
3
3
  include Spree::VatPriceCalculation
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -46,7 +46,9 @@ module Spree
46
46
  end
47
47
 
48
48
  alias_attribute :price, :amount
49
+ alias_method :price=, :amount=
49
50
  alias_attribute :compare_at_price, :compare_at_amount
51
+ alias_method :compare_at_price=, :compare_at_amount=
50
52
 
51
53
  def price_including_vat_for(price_options)
52
54
  options = price_options.merge(tax_category: variant.tax_category)
@@ -27,7 +27,7 @@ module Spree
27
27
  include Spree::TranslatableResourceSlug
28
28
  include Spree::MemoizedData
29
29
  include Spree::Metadata
30
- if defined?(Spree::Webhooks)
30
+ if defined?(Spree::Webhooks::HasWebhooks)
31
31
  include Spree::Webhooks::HasWebhooks
32
32
  end
33
33
  if defined?(Spree::VendorConcern)
@@ -39,7 +39,7 @@ module Spree
39
39
  purchasable? in_stock? backorderable?]
40
40
 
41
41
  TRANSLATABLE_FIELDS = %i[name description slug meta_description meta_keywords meta_title].freeze
42
- translates(*TRANSLATABLE_FIELDS)
42
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
43
43
 
44
44
  self::Translation.class_eval do
45
45
  before_save :set_slug
@@ -332,16 +332,17 @@ module Spree
332
332
  end
333
333
 
334
334
  def property(property_name)
335
- product_properties.joins(:property).
336
- join_translation_table(Property).
337
- find_by(Property.translation_table_alias => { name: property_name }).try(:value)
335
+ product_properties.joins(:property).find_by(Property.table_name => { name: property_name }).try(:value)
338
336
  end
339
337
 
340
338
  def set_property(property_name, property_value, property_presentation = property_name)
341
339
  ApplicationRecord.transaction do
342
340
  # Manual first_or_create to work around Mobility bug
343
341
  property = if Property.where(name: property_name).exists?
344
- Property.where(name: property_name).first
342
+ existing_property = Property.where(name: property_name).first
343
+ existing_property.presentation ||= property_presentation
344
+ existing_property.save
345
+ existing_property
345
346
  else
346
347
  Property.create(name: property_name, presentation: property_presentation)
347
348
  end
@@ -375,16 +376,24 @@ module Spree
375
376
  end
376
377
 
377
378
  def brand
378
- @brand ||= taxons.joins(:taxonomy).
379
- join_translation_table(Taxonomy).
380
- find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })
379
+ @brand ||= if Spree.use_translations?
380
+ taxons.joins(:taxonomy).
381
+ join_translation_table(Taxonomy).
382
+ find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })
383
+ else
384
+ taxons.joins(:taxonomy).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_brands_name) })
385
+ end
381
386
  end
382
387
 
383
388
  def category
384
- @category ||= taxons.joins(:taxonomy).
385
- join_translation_table(Taxonomy).
386
- order(depth: :desc).
387
- find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_categories_name) })
389
+ @category ||= if Spree.use_translations?
390
+ taxons.joins(:taxonomy).
391
+ join_translation_table(Taxonomy).
392
+ order(depth: :desc).
393
+ find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_categories_name) })
394
+ else
395
+ taxons.joins(:taxonomy).order(depth: :desc).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_categories_name) })
396
+ end
388
397
  end
389
398
 
390
399
  def taxons_for_store(store)
@@ -460,6 +469,8 @@ module Spree
460
469
  # punch slug with date prefix to allow reuse of original
461
470
  return if frozen?
462
471
 
472
+ update_column(:slug, "#{Time.current.to_i}_#{slug}"[0..254])
473
+
463
474
  translations.with_deleted.each do |t|
464
475
  t.update_column :slug, "#{Time.current.to_i}_#{t.slug}"[0..254]
465
476
  end
@@ -3,13 +3,15 @@ module Spree
3
3
  include Spree::FilterParam
4
4
  include Spree::TranslatableResource
5
5
 
6
- TRANSLATABLE_FIELDS = %i[value filter_param].freeze
7
- translates(*TRANSLATABLE_FIELDS)
6
+ TRANSLATABLE_FIELDS = %i[value].freeze
7
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
8
8
 
9
9
  self::Translation.class_eval do
10
10
  auto_strip_attributes :value
11
11
  end
12
12
 
13
+ auto_strip_attributes :value
14
+
13
15
  acts_as_list scope: :product
14
16
 
15
17
  with_options inverse_of: :product_properties do
@@ -2,7 +2,7 @@ module Spree
2
2
  class Promotion < Spree::Base
3
3
  include Spree::MultiStoreResource
4
4
  include Spree::Metadata
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
  if defined?(Spree::Security::Promotions)
@@ -3,17 +3,19 @@ module Spree
3
3
  include Spree::FilterParam
4
4
  include Spree::Metadata
5
5
  include Spree::TranslatableResource
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
 
10
- TRANSLATABLE_FIELDS = %i[name presentation filter_param].freeze
11
- translates(*TRANSLATABLE_FIELDS)
10
+ TRANSLATABLE_FIELDS = %i[presentation].freeze
11
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
12
12
 
13
13
  self::Translation.class_eval do
14
- auto_strip_attributes :name, :presentation
14
+ auto_strip_attributes :presentation
15
15
  end
16
16
 
17
+ auto_strip_attributes :name, :presentation
18
+
17
19
  has_many :property_prototypes, class_name: 'Spree::PropertyPrototype'
18
20
  has_many :prototypes, through: :property_prototypes, class_name: 'Spree::Prototype'
19
21
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Prototype < Spree::Base
3
3
  include Spree::Metadata
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Refund < Spree::Base
3
3
  include Spree::Metadata
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
  if defined?(Spree::Security::Refunds)
@@ -2,7 +2,7 @@ module Spree
2
2
  class Reimbursement < Spree::Base
3
3
  include Spree::Core::NumberGenerator.new(prefix: 'RI', length: 9)
4
4
  include Spree::NumberIdentifier
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Spree
2
2
  class ReturnAuthorization < Spree::Base
3
3
  include Spree::Core::NumberGenerator.new(prefix: 'RA', length: 9)
4
4
  include Spree::NumberIdentifier
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Spree
2
2
  class ReturnItem < Spree::Base
3
3
  COMPLETED_RECEPTION_STATUSES = %w(received given_to_customer)
4
4
 
5
- if defined?(Spree::Webhooks)
5
+ if defined?(Spree::Webhooks::HasWebhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
8
8
 
@@ -6,7 +6,7 @@ module Spree
6
6
  include Spree::NumberIdentifier
7
7
  include Spree::NumberAsParam
8
8
  include Spree::Metadata
9
- if defined?(Spree::Webhooks)
9
+ if defined?(Spree::Webhooks::HasWebhooks)
10
10
  include Spree::Webhooks::HasWebhooks
11
11
  end
12
12
  if defined?(Spree::Security::Shipments)
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class ShippingCategory < Spree::Base
3
3
  include Spree::UniqueName
4
- if defined?(Spree::Webhooks)
4
+ if defined?(Spree::Webhooks::HasWebhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
7
7
 
@@ -3,7 +3,7 @@ module Spree
3
3
  acts_as_paranoid
4
4
  include Spree::CalculatedAdjustments
5
5
  include Spree::Metadata
6
- if defined?(Spree::Webhooks)
6
+ if defined?(Spree::Webhooks::HasWebhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
9
9
  if defined?(Spree::VendorConcern)