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
[SD-1507] System should emit `product.discontinued` when a Product is discontinued (#11462)
Aleksandar Petrushev2f6809ceed97
diff --git a/api/app/models/spree/api/webhooks/product_decorator.rb b/api/app/models/spree/api/webhooks/product_decorator.rbnew file mode 100644index 0000000000..887467aa68--- /dev/null+++ b/api/app/models/spree/api/webhooks/product_decorator.rb@@ -0,0 +1,15 @@+module Spree+ module Api+ module Webhooks+ module ProductDecorator+ def discontinue!+ super+ queue_webhooks_requests!('product.discontinued')+ end+ end+ end+ end+end++Spree::Product.prepend(Spree::Api::Webhooks::ProductDecorator)+diff --git a/api/spec/models/spree/api/webhooks/product_decorator_spec.rb b/api/spec/models/spree/api/webhooks/product_decorator_spec.rbnew file mode 100644index 0000000000..3381fe72de--- /dev/null+++ b/api/spec/models/spree/api/webhooks/product_decorator_spec.rb@@ -0,0 +1,12 @@+require 'spec_helper'++describe Spree::Product do+ let(:product) { create(:product) }+ let(:body) { Spree::Api::V2::Platform::ProductSerializer.new(product).serializable_hash.to_json }++ describe '#discontinue!' do+ it 'emits the product.discontinued event' do+ expect { product.discontinue! }.to emit_webhook_event('product.discontinued')+ end+ end+end