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
Improve `StockItem#conditional_variant_touch`
Damian Legawiec9ee0dbd505b2
diff --git a/core/app/models/spree/stock_item.rb b/core/app/models/spree/stock_item.rbindex eac0efa8e9..006ee326ac 100644--- a/core/app/models/spree/stock_item.rb+++ b/core/app/models/spree/stock_item.rb@@ -93,12 +93,15 @@ module Spreeenddef conditional_variant_touch- # the variant_id changes from nil when a new stock location is added- stock_changed = (saved_change_to_count_on_hand? &&- saved_change_to_count_on_hand.any?(&:zero?)) ||- saved_change_to_variant_id?+ variant.touch if !Spree::Config.binary_inventory_cache || stock_changed?+ end- variant.touch if !Spree::Config.binary_inventory_cache || stock_changed+ def stock_changed?+ # the variant_id changes from nil when a new stock location is added+ (+ saved_change_to_count_on_hand? &&+ saved_change_to_count_on_hand.any?(&:zero?)+ ) || saved_change_to_variant_id?endendenddiff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 29dc4620ef..3c60c75519 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -399,6 +399,10 @@ module Spreedigitals.present?end+ def clear_in_stock_cache+ Rails.cache.delete(in_stock_cache_key)+ end+privatedef ensure_not_in_complete_orders@@ -450,10 +454,6 @@ module Spree"variant-#{id}-in_stock"end- def clear_in_stock_cache- Rails.cache.delete(in_stock_cache_key)- end-def disable_sku_validation?Spree::Config[:disable_sku_validation]end