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
Fixed spree events logger in development environment
Damian Legawiecb5e97052556f
diff --git a/core/app/subscribers/spree/event_log_subscriber.rb b/core/app/subscribers/spree/event_log_subscriber.rbindex 3a5151463e..667195d8da 100644--- a/core/app/subscribers/spree/event_log_subscriber.rb+++ b/core/app/subscribers/spree/event_log_subscriber.rb@@ -16,9 +16,10 @@ module Spreeclass << selfdef attach_to_notifications- return if @attached+ # Always detach first to ensure clean state after code reload+ detach_from_notifications- @subscription = ActiveSupport::Notifications.subscribe(/\.#{NAMESPACE}$/) do |name, start, finish, id, payload|+ @subscription = ActiveSupport::Notifications.subscribe(/\.#{NAMESPACE}$/) do |name, start, finish, _id, payload|log_event(name, start, finish, payload)end@@ -27,8 +28,6 @@ module Spreeenddef detach_from_notifications- return unless @attached-ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription@subscription = nil@attached = falsediff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rbindex 04c4d45616..ee365f40ba 100644--- a/core/lib/spree/core/engine.rb+++ b/core/lib/spree/core/engine.rb@@ -386,10 +386,21 @@ module SpreeRails.configuration.cache_classes ? require(c) : load(c)end+ # Re-enable lifecycle events for configured models after code reload+ # This is needed because after_commit callbacks are lost when classes are reloaded+ Rails.application.config.spree.eventable_models&.each do |model|+ model.publishes_lifecycle_events if model.respond_to?(:publishes_lifecycle_events)+ end+# Reset and re-activate event subscribers on code reload# activate! will register all subscribers from Spree.subscribersSpree::Events.reset!Spree::Events.activate!++ # Re-attach event log subscriber if enabled+ if Spree::Config.events_log_enabled+ Spree::EventLogSubscriber.attach_to_notifications+ endendendenddiff --git a/core/spec/subscribers/spree/event_log_subscriber_spec.rb b/core/spec/subscribers/spree/event_log_subscriber_spec.rbindex 810acd1ae7..322eabfef5 100644--- a/core/spec/subscribers/spree/event_log_subscriber_spec.rb+++ b/core/spec/subscribers/spree/event_log_subscriber_spec.rb@@ -19,10 +19,13 @@ RSpec.describe Spree::EventLogSubscriber doexpect(described_class.attached?).to be trueend- it 'only attaches once' do+ it 'can be called multiple times safely (for code reload support)' dodescribed_class.attach_to_notifications- expect(ActiveSupport::Notifications).not_to receive(:subscribe)+ expect(described_class.attached?).to be true++ # Calling again should still work (detaches and re-attaches)described_class.attach_to_notifications+ expect(described_class.attached?).to be trueendend