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
Simplified class settings, staff email locales and gateway options
Claudea771000ce6ec
diff --git a/spree/core/app/mailers/spree/admin_user_mailer.rb b/spree/core/app/mailers/spree/admin_user_mailer.rbindex 09c3db2585..f276f21085 100644--- a/spree/core/app/mailers/spree/admin_user_mailer.rb+++ b/spree/core/app/mailers/spree/admin_user_mailer.rb@@ -8,7 +8,7 @@ module Spree@current_store = store@reset_url = password_reset_url(token, store, redirect_url)- with_store_locale(store, preferred_locale(admin_user, store)) do+ with_store_locale(store, staff_locale(admin_user, store)) domail_template({ user: email_data(admin_user, Spree::Emails::UserSerializer), reset_url: @reset_url },to: admin_user.email, store_url: store.formatted_url@@ -18,20 +18,6 @@ module Spreeprivate- # Locale chain for admin auth emails:- # the admin's own dashboard language (persisted by the profile/language- # switcher via `PATCH /api/v3/admin/me`) → the store's configured admin- # locale → nil, which lets with_store_locale fall back to the store's- # default (storefront) locale. Blank or unavailable values fall through.- def preferred_locale(admin_user, store)- [admin_user.try(:selected_locale), store&.preferred_admin_locale]- .find { |locale| available_locale?(locale) }- end-- def available_locale?(locale)- locale.present? && I18n.available_locales.map(&:to_s).include?(locale.to_s)- end-# The dashboard SPA passes a validated redirect URL; the token is appended as# a query param, falling back to the dashboard's own reset page.def password_reset_url(token, store, redirect_url)diff --git a/spree/core/app/mailers/spree/base_mailer.rb b/spree/core/app/mailers/spree/base_mailer.rbindex 928ff5d7f6..bb9c0316b4 100644--- a/spree/core/app/mailers/spree/base_mailer.rb+++ b/spree/core/app/mailers/spree/base_mailer.rb@@ -70,6 +70,14 @@ module Spreeprotected+ # Locale for an email to a staff member or seller: their own dashboard+ # language, then the store's admin locale, then nil — which lets+ # with_store_locale fall back to the store's default. Blank or unavailable+ # values fall through.+ def staff_locale(user, store)+ [user.try(:selected_locale), store&.preferred_admin_locale].find { |locale| I18n.locale_available?(locale) }+ end+# Renders the current action's email from its Liquid template and builds# the message. The template's front matter supplies the subject, and the# plain-text part is generated from the HTML unless a `.text.liquid` sitsdiff --git a/spree/core/app/mailers/spree/seller_user_mailer.rb b/spree/core/app/mailers/spree/seller_user_mailer.rbindex de9ad22731..c530ec0817 100644--- a/spree/core/app/mailers/spree/seller_user_mailer.rb+++ b/spree/core/app/mailers/spree/seller_user_mailer.rb@@ -12,7 +12,7 @@ module Spree@current_store = store@reset_url = password_reset_url(token, store, redirect_url)- with_store_locale(store, preferred_locale(seller_user, store)) do+ with_store_locale(store, staff_locale(seller_user, store)) domail_template({ user: email_data(seller_user, Spree::Emails::UserSerializer), reset_url: @reset_url },to: seller_user.email, store_url: store.formatted_url@@ -22,17 +22,6 @@ module Spreeprivate- # The seller's own panel language, then the store's admin locale, then nil —- # which lets with_store_locale fall back to the store's default.- def preferred_locale(seller_user, store)- [seller_user.try(:selected_locale), store&.preferred_admin_locale]- .find { |locale| available_locale?(locale) }- end-- def available_locale?(locale)- locale.present? && I18n.available_locales.map(&:to_s).include?(locale.to_s)- end-# The panel passes a validated redirect URL when it has one. Without it the# panel origin is resolved server-side rather than falling back to the store# URL: a storefront link cannot reset a seller password, and the marketplacediff --git a/spree/core/app/models/spree/payment/gateway_options.rb b/spree/core/app/models/spree/payment/gateway_options.rbindex 4ae05cc7fd..38fba84c49 100644--- a/spree/core/app/models/spree/payment/gateway_options.rb+++ b/spree/core/app/models/spree/payment/gateway_options.rb@@ -10,40 +10,19 @@ module Spreeattr_reader :payment, :orderdelegate :currency, to: :payment- delegate :email, to: :order-- def statement_descriptor_suffix- order.number- end-- def customer- order.email- end-- def customer_id- order.customer_id- end-- def ip- order.last_ip_address- end-- # The payment number already names its order (`R1001-P1`), so this is- # the payment number alone rather than the two concatenated.- def order_id- payment.number- end-- def payment_id- payment.number- end-+ delegate :email, :customer_id, to: :order# Stable handle for a gateway to find its own payment back. The derived# number cannot be queried (its column is NULL on 6.0 rows) and shifts# if an earlier sibling is destroyed — nothing durable may key on it.- def payment_prefixed_id- payment.prefixed_id- end+ delegate :prefixed_id, to: :payment, prefix: true++ def statement_descriptor_suffix = order.number+ def customer = order.email+ def ip = order.last_ip_address+ # The payment number already names its order (`R1001-P1`), so this is+ # the payment number alone rather than the two concatenated.+ def order_id = payment.number+ def payment_id = payment.number# Built on the prefixed ID, not the number: a derived number shifts if# an earlier sibling payment is destroyed, and a shifted idempotency@@ -77,29 +56,12 @@ module Spreeenddef hash_methods- [- :email,- :customer,- :customer_id,- :ip,- :order_id,- :payment_id,- :payment_prefixed_id,- :idempotency_key,- :shipping,- :tax,- :subtotal,- :discount,- :currency,- :billing_address,- :shipping_address- ]+ %i[email customer customer_id ip order_id payment_id payment_prefixed_id idempotency_key shipping tax+ subtotal discount currency billing_address shipping_address]enddef to_hash- Hash[hash_methods.map do |method|- [method, send(method)]- end]+ hash_methods.index_with { |method| send(method) }endprivatediff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rbindex 5ce3877ae2..3208eacd58 100644--- a/spree/core/lib/spree/core.rb+++ b/spree/core/lib/spree/core.rb@@ -57,21 +57,29 @@ module SpreeActiveRecord::Base.connection.adapter_name.match?(/mysql|trilogy/i)end+ # Class settings hold a name rather than the class itself, so a reloaded+ # class is never served stale.+ def self.resolve_class_setting(name, value, constantize)+ raise "Spree.#{name} MUST be a String or Symbol object, not a Class object." if value.is_a?(Class)+ return unless value.is_a?(String) || value.is_a?(Symbol)++ constantize ? value.to_s.constantize : value.to_s+ end+ private_class_method :resolve_class_setting++ def self.storage_service_name(value)+ return Rails.application.config.active_storage.service unless value++ value.to_sym if value.is_a?(String) || value.is_a?(Symbol)+ end+ private_class_method :storage_service_name+def self.base_class(constantize: true)- @@base_class ||= 'Spree::Base'- if @@base_class.is_a?(Class)- raise 'Spree.base_class MUST be a String or Symbol object, not a Class object.'- elsif @@base_class.is_a?(String) || @@base_class.is_a?(Symbol)- constantize ? @@base_class.to_s.constantize : @@base_class.to_s- end+ resolve_class_setting(:base_class, @@base_class ||= 'Spree::Base', constantize)enddef self.customer_class(constantize: true)- if @@customer_class.is_a?(Class)- raise 'Spree.customer_class MUST be a String or Symbol object, not a Class object.'- elsif @@customer_class.is_a?(String) || @@customer_class.is_a?(Symbol)- constantize ? @@customer_class.to_s.constantize : @@customer_class.to_s- end+ resolve_class_setting(:customer_class, @@customer_class, constantize)end# @deprecated Spree.user_class was renamed to Spree.customer_class in 6.0; removed in 6.1.@@ -87,35 +95,15 @@ module Spreeenddef self.admin_user_class(constantize: true)- if @@admin_user_class.is_a?(Class)- raise 'Spree.admin_user_class MUST be a String or Symbol object, not a Class object.'- elsif @@admin_user_class.is_a?(String) || @@admin_user_class.is_a?(Symbol)- constantize ? @@admin_user_class.to_s.constantize : @@admin_user_class.to_s- end+ resolve_class_setting(:admin_user_class, @@admin_user_class, constantize)enddef self.private_storage_service_name- if @@private_storage_service_name- if @@private_storage_service_name.is_a?(String) || @@private_storage_service_name.is_a?(Symbol)- @@private_storage_service_name.to_sym- end- else- Rails.application.config.active_storage.service- end+ storage_service_name(@@private_storage_service_name)enddef self.public_storage_service_name- if @@public_storage_service_name- if @@public_storage_service_name.is_a?(String) || @@public_storage_service_name.is_a?(Symbol)- @@public_storage_service_name.to_sym- end- else- Rails.application.config.active_storage.service- end- end-- def self.root_domain- @@root_domain+ storage_service_name(@@public_storage_service_name)enddef self.queues@@ -210,17 +198,7 @@ module Spree# @param constantize [Boolean] whether to return the class or the string# @return [Class, String] the adapter class or its namedef self.events_adapter_class(constantize: true)- @@events_adapter_class ||= 'Spree::Events::Adapters::ActiveSupportNotifications'-- if @@events_adapter_class.is_a?(Class)- raise 'Spree.events_adapter_class MUST be a String or Symbol object, not a Class object.'- elsif @@events_adapter_class.is_a?(String) || @@events_adapter_class.is_a?(Symbol)- constantize ? @@events_adapter_class.to_s.constantize : @@events_adapter_class.to_s- end- end-- def self.google_places_api_key- @@google_places_api_key+ resolve_class_setting(:events_adapter_class, @@events_adapter_class ||= 'Spree::Events::Adapters::ActiveSupportNotifications', constantize)enddef self.always_use_translations?