Sha256: 63d76c81372bf16451ba71c08c52c54d8d065aa10d4a2ac1ac51d2515085cec3
Contents?: true
Size: 1.78 KB
Versions: 3
Compression:
Stored size: 1.78 KB
Contents
module Spree class StockMovement < Spree::Base module Webhooks extend ActiveSupport::Concern include Spree::Webhooks::HasWebhooks included do around_save :queue_webhooks_requests_for_variant_out_of_stock! around_save :queue_webhooks_requests_for_variant_back_in_stock! around_save :queue_webhooks_requests_for_product_out_of_stock! around_save :queue_webhooks_requests_for_product_back_in_stock! end def queue_webhooks_requests_for_variant_out_of_stock! variant_in_stock_before_update = variant.in_stock_or_backorderable? yield if variant_in_stock_before_update && !variant.in_stock_or_backorderable? reload stock_item.variant.queue_webhooks_requests!('variant.out_of_stock') end end def queue_webhooks_requests_for_variant_back_in_stock! variant_was_out_of_stock = !variant.in_stock_or_backorderable? yield if variant_was_out_of_stock && variant.in_stock_or_backorderable? reload variant.queue_webhooks_requests!('variant.back_in_stock') end end def queue_webhooks_requests_for_product_back_in_stock! product_was_out_of_stock = !product.any_variant_in_stock_or_backorderable? yield if product_was_out_of_stock && product.any_variant_in_stock_or_backorderable? product.queue_webhooks_requests!('product.back_in_stock') end end def queue_webhooks_requests_for_product_out_of_stock! product_was_in_stock = product.any_variant_in_stock_or_backorderable? yield if product_was_in_stock && !product.any_variant_in_stock_or_backorderable? product.queue_webhooks_requests!('product.out_of_stock') end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spree_api-4.10.1 | app/models/spree/stock_movement/webhooks.rb |
spree_api-4.10.0 | app/models/spree/stock_movement/webhooks.rb |
spree_api-4.9.0 | app/models/spree/stock_movement/webhooks.rb |