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.

[Docs] fixed subscribers registration documentation

Damian Legawiece98672cd7f6d
diff --git a/docs/developer/core-concepts/events.mdx b/docs/developer/core-concepts/events.mdx
index 8eabf0a0ac..baa4449670 100644
--- a/docs/developer/core-concepts/events.mdx
+++ b/docs/developer/core-concepts/events.mdx
@@ -455,18 +455,20 @@ Spree::Publishable::MissingSerializerError:
Subscribers in `app/subscribers/` are automatically registered during Rails initialization.
-For subscribers in other locations, register them manually in an initializer:
+For subscribers in other locations, add them to the `Spree.subscribers` array in an initializer:
```ruby config/initializers/event_subscribers.rb
Rails.application.config.after_initialize do
- MyApp::CustomSubscriber.register!
+ Spree.subscribers << MyApp::CustomSubscriber
end
```
-To unregister a subscriber:
+To remove a built-in subscriber:
-```ruby
-MyApp::CustomSubscriber.unregister!
+```ruby config/initializers/event_subscribers.rb
+Rails.application.config.after_initialize do
+ Spree.subscribers.delete(Spree::ExportSubscriber)
+end
```
## Synchronous vs Asynchronous
diff --git a/emails/README.md b/emails/README.md
index ad877c9b4c..7a6d74760a 100644
--- a/emails/README.md
+++ b/emails/README.md
@@ -142,21 +142,31 @@ end
Emails are triggered via Spree's event system. Create custom subscribers:
```ruby
-# app/subscribers/spree/custom_email_subscriber.rb
-module Spree
- module CustomEmailSubscriber
- include Spree::Event::Subscriber
+# app/subscribers/my_app/custom_email_subscriber.rb
+module MyApp
+ class CustomEmailSubscriber < Spree::Subscriber
+ subscribes_to 'customer.created'
- event_action :user_registered
+ def handle(event)
+ user_id = event.payload['id']
+ user = Spree.user_class.find_by(id: user_id)
+ return unless user
- def user_registered(event)
- user = event.payload[:user]
Spree::CustomMailer.welcome_email(user).deliver_later
end
end
end
```
+Then register the subscriber in an initializer:
+
+```ruby
+# config/initializers/spree.rb
+Rails.application.config.after_initialize do
+ Spree.subscribers << MyApp::CustomEmailSubscriber
+end
+```
+
## Disabling Emails
Disable transactional emails for a specific store: