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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add `FriendlyId` to `Store` to keep track `code` changes history
Damian Legawiecfed752b44039
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex e5b2fd5fba..6b59e9de15 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -1,18 +1,23 @@module Spreeclass Store < Spree.base_class+ include FriendlyIdinclude Spree::TranslatableResource- if defined?(Spree::Webhooks::HasWebhooks)- include Spree::Webhooks::HasWebhooks- end- if defined?(Spree::Security::Stores)- include Spree::Security::Stores- end+ include Spree::Webhooks::HasWebhooks if defined?(Spree::Webhooks::HasWebhooks)+ include Spree::Security::Stores if defined?(Spree::Security::Stores)++ #+ # Magic methods+ #+ acts_as_paranoid+ friendly_id :slug_candidates, use: [:slugged, :history], slug_column: :code, routes: :normal+ #+ # Translations+ #TRANSLATABLE_FIELDS = %i[name meta_description meta_keywords seo_title facebooktwitter instagram customer_support_email descriptionaddress contact_phone new_order_notifications_email].freezetranslates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)-self::Translation.class_eval doacts_as_paranoid# deleted translation values still need to be accessible - remove deleted_at scope@@ -32,8 +37,10 @@ module Spreepreference :weight_unit, :string, default: 'lb'preference :unit_system, :string, default: 'imperial'- acts_as_paranoid+ #+ # Associations+ #has_many :checkouts, -> { incomplete }, class_name: 'Spree::Order', inverse_of: :storehas_many :orders, class_name: 'Spree::Order'has_many :line_items, through: :orders, class_name: 'Spree::LineItem'@@ -133,11 +140,15 @@ module Spreeafter_create :import_payment_methods_from_store, if: -> { import_payment_methods_from_store_id.present? }before_destroy :validate_not_last, unless: :skip_validate_not_lastbefore_destroy :pass_default_flag_to_other_store+ after_commit :clear_cache+ after_commit :handle_code_changes, on: :update, if: -> { code_previously_changed? }+ #+ # Scopes+ #+ default_scope { order(created_at: :asc) }scope :by_url, ->(url) { where('url like ?', "%#{url}%") }- after_commit :clear_cache-delegate :iso, to: :default_country, prefix: true, allow_nil: truedef self.current(url = nil)@@ -365,5 +376,19 @@ module Spree[on_sale_taxon, new_arrivals_taxon]endend++ # code is slug, so we don't want to generate new slug when code changes+ # we use friendlyId only for history feature+ def should_generate_new_friendly_id?+ false+ end++ def slug_candidates+ []+ end++ def handle_code_changes+ # implement your custom logic here+ endendend