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.

Fix stock_item around_create callback making others fail.

Sebastian Palmab93d34501838
diff --git a/api/app/models/spree/api/webhooks/stock_item_decorator.rb b/api/app/models/spree/api/webhooks/stock_item_decorator.rb
index 6c5d630515..4de8c59bec 100644
--- a/api/app/models/spree/api/webhooks/stock_item_decorator.rb
+++ b/api/app/models/spree/api/webhooks/stock_item_decorator.rb
@@ -12,6 +12,7 @@ module Spree
def queue_webhooks_requests_for_variant_backorderable_on_create!
was_out_of_stock = variant.out_of_stock?
yield
+ reload
return unless emits_webhook_event_on_create?(variant.reload, was_out_of_stock)
variant.queue_webhooks_requests!('variant.backorderable')
@@ -27,8 +28,7 @@ module Spree
was_out_of_stock = variant.out_of_stock?
was_not_orderable = !variant.backorderable?
yield
- variant.reload
- variant.touch # changes must be reflected before instantiating the serializer
+ touch # changes must be reflected before instantiating the serializer
return unless emits_webhook_event_on_update?(variant, was_out_of_stock, was_not_orderable)
variant.queue_webhooks_requests!('variant.backorderable')
diff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
index a22a76fa69..bf9772be55 100644
--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb
@@ -31,13 +31,13 @@ describe Spree::Webhooks::HasWebhooks do
context 'after_destroy_commit' do
before { product.destroy }
- it_behaves_like 'not queueing an event request', 'product.create'
+ it_behaves_like 'not queueing an event request', 'product.destroy'
end
context 'after_update_commit' do
before { product.update(name: 'updated') }
- it_behaves_like 'not queueing an event request', 'product.create'
+ it_behaves_like 'not queueing an event request', 'product.update'
end
end
diff --git a/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb b/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb
index 898e5c20a9..dc99286513 100644
--- a/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb
+++ b/api/spec/models/spree/api/webhooks/stock_item_decorator_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Spree::Api::Webhooks::StockItemDecorator do
describe 'emitting variant.backorderable' do
- let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant).serializable_hash.to_json }
+ let(:body) { Spree::Api::V2::Platform::VariantSerializer.new(variant.reload).serializable_hash.to_json }
let(:variant) { create(:variant) }
before do