spree_core 4.7.3 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) 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/routes.rb +7 -8
  57. data/db/migrate/20210929090344_create_stock_item_stock_location_id_variant_id_coalesce_deleted_at_unique_index.rb +1 -28
  58. data/db/migrate/20230103144439_create_option_type_translations.rb +0 -1
  59. data/db/migrate/20230103151034_create_option_value_translations.rb +0 -1
  60. data/db/migrate/20230109084253_create_product_property_translations.rb +0 -1
  61. data/db/migrate/20230109105943_create_property_translations.rb +0 -2
  62. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +2 -8
  63. data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +35 -0
  64. data/db/migrate/20240514105216_add_weight_and_dimension_units_to_spree_variants.rb +6 -0
  65. data/lib/generators/spree/custom_authentication/custom_authentication_generator.rb +23 -0
  66. data/lib/generators/spree/{custom_user → custom_authentication}/templates/authentication_helpers.rb.tt +1 -14
  67. data/lib/generators/spree/custom_user/custom_user_generator.rb +3 -8
  68. data/lib/generators/spree/custom_user/templates/current_user_helpers.rb.tt +15 -0
  69. data/lib/generators/spree/custom_user/templates/migration.rb.tt +2 -2
  70. data/lib/generators/spree/dummy/dummy_generator.rb +1 -6
  71. data/lib/generators/spree/dummy/templates/rails/database.yml +19 -21
  72. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  73. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -0
  74. data/lib/spree/core/configuration.rb +11 -25
  75. data/lib/spree/core/controller_helpers/locale.rb +5 -1
  76. data/lib/spree/core/engine.rb +4 -1
  77. data/lib/spree/core/preferences/runtime_configuration.rb +43 -0
  78. data/lib/spree/core/product_duplicator.rb +2 -0
  79. data/lib/spree/core/product_filters.rb +9 -2
  80. data/lib/spree/core/runtime_configuration.rb +9 -0
  81. data/lib/spree/core/version.rb +1 -1
  82. data/lib/spree/core/webhooks.rb +13 -0
  83. data/lib/spree/core.rb +7 -0
  84. data/lib/spree/money.rb +38 -5
  85. data/lib/spree/testing_support/authorization_helpers.rb +3 -1
  86. data/lib/spree/testing_support/common_rake.rb +7 -18
  87. data/spree_core.gemspec +7 -7
  88. metadata +47 -50
  89. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +0 -5
  90. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +0 -5
  91. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +0 -66
  92. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +0 -58
  93. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +0 -59
  94. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +0 -82
  95. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +0 -5
  96. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +0 -11
  97. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +0 -11
  98. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +0 -5
@@ -3,7 +3,7 @@ module Spree
3
3
  acts_as_paranoid
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
 
@@ -14,7 +14,7 @@ module Spree
14
14
  has_many :stock_movements, inverse_of: :stock_item
15
15
 
16
16
  validates :stock_location, :variant, presence: true
17
- validates :variant_id, uniqueness: { scope: %i[stock_location_id deleted_at] }
17
+ validates :variant_id, uniqueness: { scope: :stock_location_id }, unless: :deleted_at
18
18
 
19
19
  validates :count_on_hand, numericality: {
20
20
  greater_than_or_equal_to: 0,
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class StockLocation < 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
  if defined?(Spree::Security::StockLocations)
@@ -71,6 +71,11 @@ module Spree
71
71
  stock_item(variant_id) || propagate_variant(variant)
72
72
  end
73
73
 
74
+ # Returns the count on hand number for the variant
75
+ #
76
+ # @param variant Variant instance
77
+ #
78
+ # @return [Integer]
74
79
  def count_on_hand(variant)
75
80
  stock_item(variant).try(:count_on_hand)
76
81
  end
@@ -5,7 +5,7 @@ module Spree
5
5
  min: -2**31
6
6
  }.freeze
7
7
 
8
- if defined?(Spree::Webhooks)
8
+ if defined?(Spree::Webhooks::HasWebhooks)
9
9
  include Spree::Webhooks::HasWebhooks
10
10
  end
11
11
 
@@ -4,7 +4,7 @@ module Spree
4
4
  include Spree::NumberIdentifier
5
5
  include Spree::NumberAsParam
6
6
  include Spree::Metadata
7
- if defined?(Spree::Webhooks)
7
+ if defined?(Spree::Webhooks::HasWebhooks)
8
8
  include Spree::Webhooks::HasWebhooks
9
9
  end
10
10
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Store < Spree::Base
3
3
  include Spree::TranslatableResource
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::Stores)
@@ -11,7 +11,7 @@ module Spree
11
11
  TRANSLATABLE_FIELDS = %i[name meta_description meta_keywords seo_title facebook
12
12
  twitter instagram customer_support_email description
13
13
  address contact_phone new_order_notifications_email].freeze
14
- translates(*TRANSLATABLE_FIELDS)
14
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
15
15
 
16
16
  self::Translation.class_eval do
17
17
  acts_as_paranoid
@@ -109,8 +109,6 @@ module Spree
109
109
 
110
110
  after_commit :clear_cache
111
111
 
112
- alias_attribute :contact_email, :customer_support_email
113
-
114
112
  def self.current(url = nil)
115
113
  Spree::Deprecation.warn(<<-DEPRECATION, caller)
116
114
  `Spree::Store.current` is deprecated and will be removed in Spree 5.0
@@ -2,7 +2,7 @@ module Spree
2
2
  class StoreCredit < Spree::Base
3
3
  include Spree::SingleStoreResource
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
 
@@ -10,8 +10,17 @@ module Spree
10
10
 
11
11
  validates :attachment,
12
12
  content_type: VALID_CONTENT_TYPES,
13
- dimension: { max: 256..256 },
14
- aspect_ratio: :square,
15
13
  size: { less_than_or_equal_to: 1.megabyte }
14
+
15
+ validates :attachment,
16
+ if: :is_png?,
17
+ dimension: { max: 256..256 },
18
+ aspect_ratio: :square
19
+
20
+ private
21
+
22
+ def is_png?
23
+ attachment.content_type.in?('image/png')
24
+ end
16
25
  end
17
26
  end
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class TaxCategory < Spree::Base
3
- if defined?(Spree::Webhooks)
3
+ if defined?(Spree::Webhooks::HasWebhooks)
4
4
  include Spree::Webhooks::HasWebhooks
5
5
  end
6
6
 
@@ -5,7 +5,7 @@ module Spree
5
5
  include Spree::CalculatedAdjustments
6
6
  include Spree::AdjustmentSource
7
7
  include Spree::Metadata
8
- if defined?(Spree::Webhooks)
8
+ if defined?(Spree::Webhooks::HasWebhooks)
9
9
  include Spree::Webhooks::HasWebhooks
10
10
  end
11
11
 
@@ -6,7 +6,7 @@ module Spree
6
6
  include Spree::TranslatableResource
7
7
  include Spree::TranslatableResourceSlug
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
 
@@ -48,6 +48,8 @@ module Spree
48
48
  after_update :sync_taxonomy_name
49
49
  after_touch :touch_ancestors_and_taxonomy
50
50
 
51
+ has_one :store, through: :taxonomy
52
+
51
53
  has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage'
52
54
 
53
55
  scope :for_store, ->(store) { joins(:taxonomy).where(spree_taxonomies: { store_id: store.id }) }
@@ -58,7 +60,7 @@ module Spree
58
60
  scope :for_stores, ->(stores) { joins(:taxonomy).where(spree_taxonomies: { store_id: stores.ids }) }
59
61
 
60
62
  TRANSLATABLE_FIELDS = %i[name description permalink].freeze
61
- translates(*TRANSLATABLE_FIELDS)
63
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
62
64
 
63
65
  self::Translation.class_eval do
64
66
  alias_attribute :slug, :permalink
@@ -117,7 +119,21 @@ module Spree
117
119
 
118
120
  # Creates permalink base for friendly_id
119
121
  def set_permalink
120
- translations.each(&:set_permalink)
122
+ if Spree.use_translations?
123
+ translations.each(&:set_permalink)
124
+ else
125
+ self.permalink = generate_slug
126
+ end
127
+ end
128
+
129
+ def generate_slug
130
+ if parent.present?
131
+ [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last.to_url)].join('/')
132
+ elsif permalink.blank?
133
+ name.to_url
134
+ else
135
+ permalink.to_url
136
+ end
121
137
  end
122
138
 
123
139
  def active_products
@@ -150,7 +166,7 @@ module Spree
150
166
  private
151
167
 
152
168
  def sync_taxonomy_name
153
- if saved_change_to_name? && root?
169
+ if saved_changes.key?(:name) && root?
154
170
  return if taxonomy.name.to_s == name.to_s
155
171
 
156
172
  taxonomy.update(name: name)
@@ -2,12 +2,12 @@ module Spree
2
2
  class Taxonomy < Spree::Base
3
3
  include Spree::TranslatableResource
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
 
9
9
  TRANSLATABLE_FIELDS = %i[name].freeze
10
- translates(*TRANSLATABLE_FIELDS)
10
+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)
11
11
 
12
12
  acts_as_list
13
13
 
@@ -32,7 +32,7 @@ module Spree
32
32
  end
33
33
 
34
34
  def set_root_taxon_name
35
- return unless saved_change_to_name?
35
+ return unless saved_changes.key?(:name)
36
36
  return if name.to_s == root.name.to_s
37
37
 
38
38
  root.update(name: name)
@@ -5,7 +5,7 @@ module Spree
5
5
 
6
6
  include Spree::MemoizedData
7
7
  include Spree::Metadata
8
- if defined?(Spree::Webhooks)
8
+ if defined?(Spree::Webhooks::HasWebhooks)
9
9
  include Spree::Webhooks::HasWebhooks
10
10
  end
11
11
 
@@ -122,9 +122,14 @@ module Spree
122
122
  self.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont search_by_product_name_or_sku)
123
123
 
124
124
  def self.product_name_or_sku_cont(query)
125
- joins(:product).join_translation_table(Product).
126
- where("LOWER(#{Product.translation_table_alias}.name) LIKE LOWER(:query)
127
- OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")
125
+ if Spree.use_translations?
126
+ joins(:product).
127
+ join_translation_table(Product).
128
+ where("LOWER(#{Product.translation_table_alias}.name) LIKE LOWER(:query)
129
+ OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")
130
+ else
131
+ joins(:product).where("LOWER(#{Product.table_name}.name) LIKE LOWER(:query) OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")
132
+ end
128
133
  end
129
134
 
130
135
  def self.search_by_product_name_or_sku(query)
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class WishedItem < 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 Wishlist < 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 Zone < 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
 
@@ -9,6 +9,7 @@ module Spree
9
9
  def call(address:, address_params:)
10
10
  address_params[:country_id] ||= address.country_id
11
11
  address_params = fill_country_and_state_ids(address_params)
12
+ address_params[:user_id] = address.user_id if address.user_id.present?
12
13
 
13
14
  if address&.editable?
14
15
  address.update(address_params) ? success(address) : failure(address)
@@ -4,22 +4,24 @@ module Spree
4
4
  prepend Spree::ServiceModule::Base
5
5
 
6
6
  def call
7
- # GEO
8
- Countries.call
9
- States.call
10
- Zones.call
7
+ Spree::Webhooks.disable_webhooks do
8
+ # GEO
9
+ Countries.call
10
+ States.call
11
+ Zones.call
11
12
 
12
- # user roles
13
- Roles.call
13
+ # user roles
14
+ Roles.call
14
15
 
15
- # additional data
16
- DefaultReimbursementTypes.call
17
- ShippingCategories.call
18
- StoreCreditCategories.call
16
+ # additional data
17
+ DefaultReimbursementTypes.call
18
+ ShippingCategories.call
19
+ StoreCreditCategories.call
19
20
 
20
- # store & stock location
21
- Stores.call
22
- StockLocations.call
21
+ # store & stock location
22
+ Stores.call
23
+ StockLocations.call
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  default_store = Spree::Store.default
8
8
 
9
9
  if default_store.persisted?
10
- default_store.update!(default_country_id: Spree::Config[:default_country_id])
10
+ default_store.update!(default_country: Spree::Country.first)
11
11
  else
12
12
  Spree::Store.new do |s|
13
13
  s.name = 'Spree Demo Site'
@@ -16,7 +16,7 @@ module Spree
16
16
  s.mail_from_address = 'no-reply@example.com'
17
17
  s.customer_support_email = 'support@example.com'
18
18
  s.default_currency = 'USD'
19
- s.default_country_id = Spree::Config[:default_country_id]
19
+ s.default_country = Spree::Country.first
20
20
  s.default_locale = I18n.locale
21
21
  s.seo_title = 'Spree Commerce Demo Shop'
22
22
  s.meta_description = 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'
@@ -11,7 +11,7 @@ module Spree
11
11
  products = by_price(products)
12
12
  products = by_sku(products)
13
13
 
14
- products = select_translatable_fields(products)
14
+ products = select_translatable_fields(products) if Spree.use_translations?
15
15
 
16
16
  products.distinct
17
17
  end
@@ -12,5 +12,6 @@ Mobility.configure do |config|
12
12
  locale_accessors
13
13
  presence
14
14
  dirty
15
+ column_fallback
15
16
  end
16
17
  end
data/config/routes.rb CHANGED
@@ -2,6 +2,11 @@
2
2
  # see: https://github.com/rails/rails/issues/34872
3
3
  Rails.application.routes.draw do
4
4
  direct :cdn_image do |model, options|
5
+ options[:host] = Spree.cdn_host if Spree.cdn_host.present?
6
+ options[:host] ||= Rails.application.routes.default_url_options[:host]
7
+
8
+ options[:only_path] = true if options[:host].blank?
9
+
5
10
  if model.blob.service_name == 'cloudinary' && defined?(Cloudinary)
6
11
  if model.class.method_defined?(:has_mvariation)
7
12
  Cloudinary::Utils.cloudinary_url(model.blob.key,
@@ -17,10 +22,7 @@ Rails.application.routes.draw do
17
22
  :rails_service_blob_proxy,
18
23
  model.signed_id,
19
24
  model.filename,
20
- options.merge(
21
- host: Spree.cdn_host || Rails.application.routes.default_url_options[:host],
22
- port: Rails.application.routes.default_url_options[:port]
23
- )
25
+ options
24
26
  )
25
27
  else
26
28
  signed_blob_id = model.blob.signed_id
@@ -32,10 +34,7 @@ Rails.application.routes.draw do
32
34
  signed_blob_id,
33
35
  variation_key,
34
36
  filename,
35
- options.merge(
36
- host: Spree.cdn_host || Rails.application.routes.default_url_options[:host],
37
- port: Rails.application.routes.default_url_options[:port]
38
- )
37
+ options
39
38
  )
40
39
  end
41
40
  end
@@ -1,32 +1,5 @@
1
1
  class CreateStockItemStockLocationIdVariantIdCoalesceDeletedAtUniqueIndex < ActiveRecord::Migration[5.2]
2
2
  def change
3
- remove_index :spree_stock_items, name: :stock_item_by_loc_var_id_deleted_at
4
- reversible do |dir|
5
- dir.up do
6
- execute <<-SQL
7
- CREATE UNIQUE INDEX stock_item_by_loc_var_id_deleted_at
8
- ON spree_stock_items(
9
- stock_location_id,
10
- variant_id,
11
- (COALESCE(deleted_at, CAST('1970-01-01' AS #{deleted_at_data_type})))
12
- );
13
- SQL
14
- end
15
-
16
- dir.down do
17
- remove_index :spree_stock_items, name: :stock_item_by_loc_var_id_deleted_at
18
- end
19
- end
20
- end
21
-
22
- private
23
-
24
- def deleted_at_data_type
25
- case ActiveRecord::Base.connection.adapter_name
26
- when 'Mysql2'
27
- 'DATETIME'
28
- when 'PostgreSQL'
29
- 'TIMESTAMP'
30
- end
3
+ # this migration was broken and is fixed in the following migration
31
4
  end
32
5
  end
@@ -9,7 +9,6 @@ class CreateOptionTypeTranslations < ActiveRecord::Migration[6.1]
9
9
  create_table :spree_option_type_translations do |t|
10
10
 
11
11
  # Translated attribute(s)
12
- t.string :name
13
12
  t.string :presentation
14
13
 
15
14
  t.string :locale, null: false
@@ -9,7 +9,6 @@ class CreateOptionValueTranslations < ActiveRecord::Migration[6.1]
9
9
  create_table :spree_option_value_translations do |t|
10
10
 
11
11
  # Translated attribute(s)
12
- t.string :name
13
12
  t.string :presentation
14
13
 
15
14
  t.string :locale, null: false
@@ -9,7 +9,6 @@ class CreateProductPropertyTranslations < ActiveRecord::Migration[6.1]
9
9
  create_table :spree_product_property_translations do |t|
10
10
  # Translated attribute(s)
11
11
  t.string :value
12
- t.string :filter_param
13
12
 
14
13
  t.string :locale, null: false
15
14
  t.references :spree_product_property, null: false, foreign_key: true, index: false
@@ -8,9 +8,7 @@ class CreatePropertyTranslations < ActiveRecord::Migration[6.1]
8
8
  else
9
9
  create_table :spree_property_translations do |t|
10
10
  # Translated attribute(s)
11
- t.string :name
12
11
  t.string :presentation
13
- t.string :filter_param
14
12
 
15
13
  t.string :locale, null: false
16
14
  t.references :spree_property, null: false, foreign_key: true, index: false
@@ -1,15 +1,9 @@
1
1
  class BackfillFriendlyIdSlugLocale < ActiveRecord::Migration[6.1]
2
- DEFAULT_LOCALE = 'en'
3
-
4
2
  def up
5
- ActiveRecord::Base.connection.execute("
6
- UPDATE friendly_id_slugs SET locale = '#{DEFAULT_LOCALE}'
7
- ")
3
+ FriendlyId::Slug.unscoped.update_all(locale: Spree::Store.default.default_locale)
8
4
  end
9
5
 
10
6
  def down
11
- ActiveRecord::Base.connection.execute("
12
- UPDATE friendly_id_slugs SET locale = NULL
13
- ")
7
+ FriendlyId::Slug.unscoped.update_all(locale: nil)
14
8
  end
15
9
  end
@@ -0,0 +1,35 @@
1
+ class FixSpreeStockItemUniqueIndex < ActiveRecord::Migration[6.1]
2
+ def change
3
+ remove_index :spree_stock_items, name: 'stock_item_by_loc_var_id_deleted_at' if index_exists?(:spree_stock_items, [:stock_location_id, :variant_id], name: 'stock_item_by_loc_var_id_deleted_at')
4
+
5
+ unless index_exists?(:spree_stock_items, ['variant_id', 'stock_location_id'], name: 'index_spree_stock_items_unique_without_deleted_at')
6
+ # MySQL doesn't support partial indexes
7
+ if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
8
+ reversible do |dir|
9
+ dir.up do
10
+ execute <<-SQL
11
+ CREATE UNIQUE INDEX index_spree_stock_items_unique_without_deleted_at
12
+ ON spree_stock_items(
13
+ stock_location_id,
14
+ variant_id,
15
+ (COALESCE(deleted_at, CAST('1970-01-01' AS DATETIME)))
16
+ );
17
+ SQL
18
+ end
19
+
20
+ dir.down do
21
+ remove_index :spree_stock_items, name: :index_spree_stock_items_unique_without_deleted_at
22
+ end
23
+ end
24
+ else
25
+ add_index(
26
+ :spree_stock_items,
27
+ ['variant_id', 'stock_location_id'],
28
+ name: 'index_spree_stock_items_unique_without_deleted_at',
29
+ unique: true,
30
+ where: 'deleted_at IS NULL',
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ class AddWeightAndDimensionUnitsToSpreeVariants < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :spree_variants, :weight_unit, :string, if_not_exists: true
4
+ add_column :spree_variants, :dimensions_unit, :string, if_not_exists: true
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ class CustomAuthenticationGenerator < Rails::Generators::Base
3
+ desc 'Set up a Spree installation with a custom authentication helpers'
4
+
5
+ def self.source_paths
6
+ paths = superclass.source_paths
7
+ paths << File.expand_path('templates', __dir__)
8
+ paths.flatten
9
+ end
10
+
11
+ def generate
12
+ template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb'
13
+
14
+ file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
15
+ send(file_action, 'config/initializers/spree.rb') do
16
+ %Q{
17
+ Rails.application.config.to_prepare do
18
+ require_dependency 'spree/authentication_helpers'
19
+ end\n}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,14 +1,4 @@
1
1
  module Spree
2
- module CurrentUserHelpers
3
- def self.included(receiver)
4
- receiver.send :helper_method, :spree_current_user
5
- end
6
-
7
- def spree_current_user
8
- current_user
9
- end
10
- end
11
-
12
2
  module AuthenticationHelpers
13
3
  def self.included(receiver)
14
4
  receiver.send :helper_method, :spree_login_path
@@ -30,7 +20,4 @@ module Spree
30
20
  end
31
21
  end
32
22
 
33
- ApplicationController.include Spree::AuthenticationHelpers
34
- ApplicationController.include Spree::CurrentUserHelpers
35
-
36
- Spree::Api::BaseController.include Spree::CurrentUserHelpers
23
+ ApplicationController.include Spree::AuthenticationHelpers if defined?(ApplicationController)
@@ -20,24 +20,19 @@ module Spree
20
20
 
21
21
  def generate
22
22
  migration_template 'migration.rb.tt', 'db/migrate/add_spree_fields_to_custom_user_table.rb'
23
- template 'authentication_helpers.rb.tt', 'lib/spree/authentication_helpers.rb'
23
+ template 'current_user_helpers.rb.tt', 'lib/spree/current_user_helpers.rb'
24
24
 
25
25
  file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
26
26
  send(file_action, 'config/initializers/spree.rb') do
27
27
  %Q{
28
28
  Rails.application.config.to_prepare do
29
- require_dependency 'spree/authentication_helpers'
29
+ require_dependency 'spree/current_user_helpers'
30
30
  end\n}
31
31
  end
32
32
  end
33
33
 
34
34
  def self.next_migration_number(dirname)
35
- if ApplicationRecord.timestamped_migrations
36
- sleep 1 # make sure to get a different migration every time
37
- Time.new.utc.strftime('%Y%m%d%H%M%S')
38
- else
39
- format('%.3d', (current_migration_number(dirname) + 1))
40
- end
35
+ format('%.3d', (current_migration_number(dirname) + 1))
41
36
  end
42
37
 
43
38
  def klass
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module CurrentUserHelpers
3
+ def self.included(receiver)
4
+ receiver.send :helper_method, :spree_current_user
5
+ end
6
+
7
+ def spree_current_user
8
+ current_user
9
+ end
10
+ end
11
+ end
12
+
13
+
14
+ ApplicationController.include Spree::CurrentUserHelpers if defined?(ApplicationController)
15
+ Spree::Api::BaseController.include Spree::CurrentUserHelpers if defined?(Spree::Api::BaseController)
@@ -1,7 +1,7 @@
1
1
  class AddSpreeFieldsToCustomUserTable < ActiveRecord::Migration[4.2]
2
2
  def up
3
3
  add_column <%= table_name.inspect %>, :spree_api_key, :string, limit: 48
4
- add_column <%= table_name.inspect %>, :ship_address_id, :integer
5
- add_column <%= table_name.inspect %>, :bill_address_id, :integer
4
+ add_column <%= table_name.inspect %>, :ship_address_id, :bigint
5
+ add_column <%= table_name.inspect %>, :bill_address_id, :bigint
6
6
  end
7
7
  end
@@ -29,10 +29,9 @@ module Spree
29
29
  # calling slice on a Thor::CoreExtensions::HashWithIndifferentAccess
30
30
  # object has been known to return nil
31
31
  opts = {}.merge(options).slice(*PASSTHROUGH_OPTIONS)
32
- opts[:database] = 'postgresql' if opts[:database].blank?
32
+ opts[:database] = 'sqlite3' if opts[:database].blank?
33
33
  opts[:force] = true
34
34
  opts[:skip_bundle] = true
35
- opts[:skip_gemfile] = true
36
35
  opts[:skip_git] = true
37
36
  opts[:skip_listen] = true
38
37
  opts[:skip_rc] = true
@@ -57,10 +56,6 @@ module Spree
57
56
  template 'rails/test.rb', "#{dummy_path}/config/environments/test.rb", force: true
58
57
  template 'rails/script/rails', "#{dummy_path}/spec/dummy/script/rails", force: true
59
58
  template 'initializers/devise.rb', "#{dummy_path}/config/initializers/devise.rb", force: true
60
-
61
- if lib_name == 'spree/backend'
62
- template 'package.json', "#{dummy_path}/package.json", force: true
63
- end
64
59
  end
65
60
 
66
61
  def test_dummy_inject_extension_requirements