Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add store settings through typed_store using json/jsonb respectively.

Matthew Kennedya443825335d4
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index 0079db88b8..f707fb2218 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -81,12 +81,6 @@ module Spree
preference :storefront_taxons_path, :string, default: 't'
preference :storefront_pages_path, :string, default: 'pages'
- # Spree Digital Asset Configurations
- preference :authorized_clicks, :integer, default: 3 # number of times a customer can download a digital file
- preference :authorized_days, :integer, default: 2 # number of days after initial purchase the customer can download a file
- preference :keep_digitals, :boolean, default: false # should digitals be kept around after the associated product is destroyed
- preference :s3_expiration_seconds, :integer, default: 10 # number of seconds before an s3 link expires
-
attr_writer :searcher_class
end
end
diff --git a/core/app/models/spree/digital_link.rb b/core/app/models/spree/digital_link.rb
index 3056d83197..f512e95eb5 100644
--- a/core/app/models/spree/digital_link.rb
+++ b/core/app/models/spree/digital_link.rb
@@ -1,13 +1,12 @@
module Spree
class DigitalLink < Spree::Base
- has_secure_token :secret
+ has_secure_token
belongs_to :digital
- validates :digital, presence: true
-
belongs_to :line_item
before_validation :set_defaults, on: :create
+ validates :digital, presence: true
# Can this link stil be used? It is valid if it's less than 24 hours
# old and was not accessed more than 3 times
@@ -36,8 +35,6 @@ module Spree
private
- # Populating the secret automatically and zero'ing the access_counter
- # (otherwise it might turn out to be NULL)
def set_defaults
self.access_counter ||= 0
end
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 247ae266f1..9e9658ddb6 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -1,5 +1,12 @@
module Spree
class Store < Spree::Base
+ # Spree Store Settings
+ typed_store :settings do |s|
+ # Spree Digital Asset Configurations
+ s.integer :digital_asset_authorized_clicks, default: 3, null: false # number of times a customer can download a digital file.
+ s.integer :digital_asset_authorized_days, default: 2, null: false # number of days after initial purchase the customer can download a file.
+ end
+
MAILER_LOGO_CONTENT_TYPES = ['image/png', 'image/jpg', 'image/jpeg'].freeze
FAVICON_CONTENT_TYPES = ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon'].freeze
diff --git a/core/db/migrate/20210929091444_create_spree_digital_links.rb b/core/db/migrate/20210929091444_create_spree_digital_links.rb
index 7462c10e01..ee2750b241 100644
--- a/core/db/migrate/20210929091444_create_spree_digital_links.rb
+++ b/core/db/migrate/20210929091444_create_spree_digital_links.rb
@@ -8,6 +8,6 @@ class CreateSpreeDigitalLinks < ActiveRecord::Migration[5.2]
t.timestamps
end
- add_index :spree_digital_links, :secret unless index_exists?(:spree_digital_links, :secret)
+ add_index :spree_digital_links, :secret, unique: true unless index_exists?(:spree_digital_links, :secret)
end
end
diff --git a/core/db/migrate/20210930143043_rename_secret_to_token_on_spree_digital_links.rb b/core/db/migrate/20210930143043_rename_secret_to_token_on_spree_digital_links.rb
new file mode 100644
index 0000000000..568e85f6cf
--- /dev/null
+++ b/core/db/migrate/20210930143043_rename_secret_to_token_on_spree_digital_links.rb
@@ -0,0 +1,5 @@
+class RenameSecretToTokenOnSpreeDigitalLinks < ActiveRecord::Migration[5.2]
+ def change
+ rename_column :spree_digital_links, :secret, :token
+ end
+end
diff --git a/core/db/migrate/20210930155649_add_settings_to_spree_stores.rb b/core/db/migrate/20210930155649_add_settings_to_spree_stores.rb
new file mode 100644
index 0000000000..f10feb5440
--- /dev/null
+++ b/core/db/migrate/20210930155649_add_settings_to_spree_stores.rb
@@ -0,0 +1,11 @@
+class AddSettingsToSpreeStores < ActiveRecord::Migration[5.2]
+ def change
+ change_table :spree_stores do |t|
+ if t.respond_to? :jsonb
+ add_column :spree_stores, :settings, :jsonb
+ else
+ add_column :spree_stores, :settings, :json
+ end
+ end
+ end
+end
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index 6e8bec9022..24eae1dea4 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -18,6 +18,7 @@ require 'mini_magick'
require 'ransack'
require 'state_machines-activerecord'
require 'active_storage_validations'
+require 'activerecord-typedstore'
# This is required because ActiveModel::Validations#invalid? conflicts with the
# invalid state of a Payment. In the future this should be removed.
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 117551abfb..1325b18eef 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -54,4 +54,5 @@ Gem::Specification.new do |s|
s.add_dependency 'mini_magick', '~> 4.9', '>= 4.9.4'
s.add_dependency 'image_processing', '~> 1.2'
s.add_dependency 'active_storage_validations', '~> 0.9'
+ s.add_dependency 'activerecord-typedstore'
end