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
Renamed `destroyed` event to `deleted`
Damian Legawiec1d4a5da21dd0
diff --git a/core/app/models/concerns/spree/publishable.rb b/core/app/models/concerns/spree/publishable.rbindex ef33f23a32..76321a8e41 100644--- a/core/app/models/concerns/spree/publishable.rb+++ b/core/app/models/concerns/spree/publishable.rb@@ -69,19 +69,19 @@ module Spree# Enable automatic lifecycle event publishing## @param options [Hash] Options for lifecycle events- # @option options [Array<Symbol>] :only Limit to specific events (:create, :update, :destroy)+ # @option options [Array<Symbol>] :only Limit to specific events (:create, :update, :delete)# @option options [Array<Symbol>] :except Exclude specific events# @return [void]## @example# publishes_lifecycle_events- # publishes_lifecycle_events only: [:create, :destroy]+ # publishes_lifecycle_events only: [:create, :delete]# publishes_lifecycle_events except: [:update]#def publishes_lifecycle_events(options = {})self.lifecycle_events_enabled = true- events = [:create, :update, :destroy]+ events = [:create, :update, :delete]events &= Array(options[:only]) if options[:only]events -= Array(options[:except]) if options[:except]@@ -93,9 +93,9 @@ module Spreeafter_commit :publish_update_event, on: :update, if: :should_publish_events?end- if events.include?(:destroy)+ if events.include?(:delete)before_destroy :capture_pre_destroy_payload, if: :should_publish_events?- after_commit :publish_destroy_event, on: :destroy, if: :should_publish_events?+ after_commit :publish_delete_event, on: :destroy, if: :should_publish_events?endend@@ -242,11 +242,11 @@ module Spreepublish_event("#{event_prefix}.updated")end- def publish_destroy_event- # For destroy, we need to capture the data before it's gone+ def publish_delete_event+ # For delete, we need to capture the data before it's gone# The after_commit runs after the record is deleted, so we use# the previously captured payload- publish_event("#{event_prefix}.destroyed", @_pre_destroy_payload || event_payload)+ publish_event("#{event_prefix}.deleted", @_pre_destroy_payload || event_payload)enddef capture_pre_destroy_payloaddiff --git a/core/lib/spree/testing_support/lifecycle_events.rb b/core/lib/spree/testing_support/lifecycle_events.rbindex e3072da761..8f5b740c22 100644--- a/core/lib/spree/testing_support/lifecycle_events.rb+++ b/core/lib/spree/testing_support/lifecycle_events.rb@@ -25,10 +25,10 @@ shared_examples_for 'lifecycle events' do |factory: nil, event_prefix: nil|endend- describe "#{described_class.event_prefix}.destroyed" do- it 'publishes destroyed event when record is destroyed' do+ describe "#{described_class.event_prefix}.deleted" do+ it 'publishes deleted event when record is deleted' dorecord = create(lifecycle_factory)- expect(record).to receive(:publish_event).with("#{lifecycle_event_prefix}.destroyed", kind_of(Hash))+ expect(record).to receive(:publish_event).with("#{lifecycle_event_prefix}.deleted", kind_of(Hash))allow(record).to receive(:publish_event).with(anything)record.destroy!diff --git a/core/spec/models/concerns/spree/publishable_spec.rb b/core/spec/models/concerns/spree/publishable_spec.rbindex a0da8813c6..85b22496f5 100644--- a/core/spec/models/concerns/spree/publishable_spec.rb+++ b/core/spec/models/concerns/spree/publishable_spec.rb@@ -213,7 +213,7 @@ RSpec.describe Spree::Publishable doit 'excludes specified callbacks' doexpect(except_class._commit_callbacks.map(&:filter)).to include(:publish_create_event)expect(except_class._commit_callbacks.map(&:filter)).not_to include(:publish_update_event)- expect(except_class._commit_callbacks.map(&:filter)).to include(:publish_destroy_event)+ expect(except_class._commit_callbacks.map(&:filter)).to include(:publish_delete_event)endenddiff --git a/core/spec/models/spree/customer_return_spec.rb b/core/spec/models/spree/customer_return_spec.rbindex f77cf30374..cac9a981d6 100644--- a/core/spec/models/spree/customer_return_spec.rb+++ b/core/spec/models/spree/customer_return_spec.rb@@ -31,10 +31,10 @@ describe Spree::CustomerReturn, type: :model doendend- describe 'customer_return.destroyed' do- it 'publishes destroyed event when record is destroyed' do+ describe 'customer_return.deleted' do+ it 'publishes deleted event when record is destroyed' dorecord = create(:customer_return)- expect(record).to receive(:publish_event).with('customer_return.destroyed', kind_of(Hash))+ expect(record).to receive(:publish_event).with('customer_return.deleted', kind_of(Hash))allow(record).to receive(:publish_event).with(anything)record.destroy!diff --git a/core/spec/models/spree/gift_card_batch_spec.rb b/core/spec/models/spree/gift_card_batch_spec.rbindex fde043b17b..ca72ca8eb7 100644--- a/core/spec/models/spree/gift_card_batch_spec.rb+++ b/core/spec/models/spree/gift_card_batch_spec.rb@@ -24,10 +24,10 @@ RSpec.describe Spree::GiftCardBatch, type: :model doendend- describe 'gift_card_batch.destroyed' do- it 'publishes destroyed event when record is destroyed' do+ describe 'gift_card_batch.deleted' do+ it 'publishes deleted event when record is destroyed' dorecord = create(:gift_card_batch, gift_card_batch_attrs)- expect(record).to receive(:publish_event).with('gift_card_batch.destroyed', kind_of(Hash))+ expect(record).to receive(:publish_event).with('gift_card_batch.deleted', kind_of(Hash))allow(record).to receive(:publish_event).with(anything)record.destroy!diff --git a/core/spec/models/spree/return_authorization_spec.rb b/core/spec/models/spree/return_authorization_spec.rbindex 51ad7e9006..f278ad2aef 100644--- a/core/spec/models/spree/return_authorization_spec.rb+++ b/core/spec/models/spree/return_authorization_spec.rb@@ -35,10 +35,10 @@ describe Spree::ReturnAuthorization, type: :model doendend- describe 'return_authorization.destroyed' do- it 'publishes destroyed event when record is destroyed' do+ describe 'return_authorization.deleted' do+ it 'publishes deleted event when record is destroyed' dorecord = create(:return_authorization)- expect(record).to receive(:publish_event).with('return_authorization.destroyed', kind_of(Hash))+ expect(record).to receive(:publish_event).with('return_authorization.deleted', kind_of(Hash))allow(record).to receive(:publish_event).with(anything)record.destroy!diff --git a/core/spec/models/spree/wishlist_spec.rb b/core/spec/models/spree/wishlist_spec.rbindex bf049f319b..98b5e8c246 100644--- a/core/spec/models/spree/wishlist_spec.rb+++ b/core/spec/models/spree/wishlist_spec.rb@@ -30,10 +30,10 @@ describe Spree::Wishlist, type: :model doendend- describe 'wishlist.destroyed' do- it 'publishes destroyed event when record is destroyed' do+ describe 'wishlist.deleted' do+ it 'publishes deleted event when record is destroyed' dorecord = create(:wishlist, user: user, store: store)- expect(record).to receive(:publish_event).with('wishlist.destroyed', kind_of(Hash))+ expect(record).to receive(:publish_event).with('wishlist.deleted', kind_of(Hash))allow(record).to receive(:publish_event).with(anything)record.destroy!diff --git a/docs/developer/customization/event-subscribers.mdx b/docs/developer/customization/event-subscribers.mdxindex bffb4f95b3..578ce0ea7b 100644--- a/docs/developer/customization/event-subscribers.mdx+++ b/docs/developer/customization/event-subscribers.mdx@@ -148,11 +148,11 @@ Models that include `Spree::Publishable` and call `publishes_lifecycle_events` a| Event Pattern | Description ||---------------|-------------|-| `{model}.create` | Record was created |-| `{model}.update` | Record was updated |-| `{model}.destroy` | Record was deleted |+| `{model}.created` | Record was created |+| `{model}.updated` | Record was updated |+| `{model}.deleted` | Record was deleted |-For example, `Spree::Price` publishes `price.create`, `price.update`, and `price.destroy`.+For example, `Spree::Price` publishes `price.created`, `price.updated`, and `price.deleted`.Models with lifecycle events enabled include: `Order`, `Payment`, `Price`, `Shipment`, `Variant`, `LineItem`, `StockItem`, and many others.@@ -160,34 +160,46 @@ Models with lifecycle events enabled include: `Order`, `Payment`, `Price`, `Ship| Event | Description ||-------|-------------|-| `order.create` | Order was created |-| `order.update` | Order was updated |-| `order.complete` | Order checkout completed |-| `order.cancel` | Order was canceled |-| `order.resume` | Canceled order was resumed |+| `order.created` | Order was created |+| `order.updated` | Order was updated |+| `order.completed` | Order checkout completed |+| `order.canceled` | Order was canceled |+| `order.resumed` | Canceled order was resumed |+| `order.paid` | Order is fully paid |+| `order.shipped` | All order shipments are shipped |### Shipment Events| Event | Description ||-------|-------------|-| `shipment.create` | Shipment was created |-| `shipment.update` | Shipment was updated |-| `shipment.ship` | Shipment was shipped |+| `shipment.created` | Shipment was created |+| `shipment.updated` | Shipment was updated |+| `shipment.shipped` | Shipment was shipped |+| `shipment.canceled` | Shipment was canceled |+| `shipment.resumed` | Shipment was resumed |### Payment Events| Event | Description ||-------|-------------|-| `payment.create` | Payment was created |-| `payment.update` | Payment was updated |+| `payment.created` | Payment was created |+| `payment.updated` | Payment was updated |+| `payment.paid` | Payment was completed |### Price Events| Event | Description ||-------|-------------|-| `price.create` | Price was created |-| `price.update` | Price was updated |-| `price.destroy` | Price was deleted |+| `price.created` | Price was created |+| `price.updated` | Price was updated |+| `price.deleted` | Price was deleted |++### Stock Events++| Event | Description |+|-------|-------------|+| `product.out_of_stock` | Product has no stock left for any variant |+| `product.back_in_stock` | Product was out of stock and now has stock again |### Product Events