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.

Fixed issue #13437 - Promotion rule caching issue when editing rules … (#13439)

Damian Legawiecea3861fe2316
diff --git a/core/app/models/spree/promotion/rules/product.rb b/core/app/models/spree/promotion/rules/product.rb
index f461e63d85..e74443a690 100644
--- a/core/app/models/spree/promotion/rules/product.rb
+++ b/core/app/models/spree/promotion/rules/product.rb
@@ -100,6 +100,9 @@ module Spree
)
end
+ # Invalidate cache after bulk operations
+ touch
+
# Clear memoized values
@eligible_product_ids = nil
end
diff --git a/core/app/models/spree/promotion/rules/user.rb b/core/app/models/spree/promotion/rules/user.rb
index e99cfaeb00..aca7829142 100644
--- a/core/app/models/spree/promotion/rules/user.rb
+++ b/core/app/models/spree/promotion/rules/user.rb
@@ -61,6 +61,9 @@ module Spree
)
end
+ # Invalidate cache after bulk operations
+ touch
+
# Clear memoized values
@eligible_user_ids = nil
end
diff --git a/core/spec/models/spree/promotion/rules/product_spec.rb b/core/spec/models/spree/promotion/rules/product_spec.rb
index 2696939609..9fa1755b3a 100644
--- a/core/spec/models/spree/promotion/rules/product_spec.rb
+++ b/core/spec/models/spree/promotion/rules/product_spec.rb
@@ -178,5 +178,17 @@ describe Spree::Promotion::Rules::Product, type: :model do
rule.save!
expect(rule.reload.eligible_product_ids).to match_array(products.map(&:id))
end
+
+ it 'touches the record to invalidate cache' do
+ rule.product_ids_to_add = [products.first.id]
+ rule.save!
+ original_updated_at = rule.updated_at
+
+ rule.update_column(:updated_at, 1.day.ago)
+ rule.product_ids_to_add = [products.second.id]
+ rule.save!
+
+ expect(rule.reload.updated_at).to be > original_updated_at
+ end
end
end
diff --git a/core/spec/models/spree/promotion/rules/user_spec.rb b/core/spec/models/spree/promotion/rules/user_spec.rb
index ec9ca97b66..5a1ac30740 100644
--- a/core/spec/models/spree/promotion/rules/user_spec.rb
+++ b/core/spec/models/spree/promotion/rules/user_spec.rb
@@ -63,5 +63,17 @@ describe Spree::Promotion::Rules::User, type: :model do
rule.save!
expect(rule.users).to include(random_user, user_placing_order)
end
+
+ it 'touches the record to invalidate cache' do
+ rule.user_ids_to_add = [random_user.id]
+ rule.save!
+ original_updated_at = rule.updated_at
+
+ rule.update_column(:updated_at, 1.day.ago)
+ rule.user_ids_to_add = [user_placing_order.id]
+ rule.save!
+
+ expect(rule.reload.updated_at).to be > original_updated_at
+ end
end
end