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
Expire Price List cache key when adding/removing products
Damian Legawiece682bd0f1953
diff --git a/core/app/models/spree/price_list.rb b/core/app/models/spree/price_list.rbindex 291c7d0865..9a21d4dce3 100644--- a/core/app/models/spree/price_list.rb+++ b/core/app/models/spree/price_list.rb@@ -155,6 +155,7 @@ module Spree# Use upsert_all with on_duplicate: :skip to handle race conditionsSpree::Price.upsert_all(prices_to_insert, on_duplicate: :skip)touch_variants(variant_ids)+ touchend# Removes products from the price list@@ -165,10 +166,13 @@ module Spreereturn if product_ids.blank?variant_ids = Spree::Variant.where(product_id: product_ids).distinct.pluck(:id)+ return if variant_ids.empty?+# Use delete_all for hard delete - this bypasses acts_as_paranoid# which is required for the unique index to work when re-adding productsprices.where(variant_id: variant_ids).delete_alltouch_variants(variant_ids)+ touchend# Bulk update prices using upsert_all for performancediff --git a/core/spec/models/spree/price_list_spec.rb b/core/spec/models/spree/price_list_spec.rbindex b5ac11c6a2..238912f224 100644--- a/core/spec/models/spree/price_list_spec.rb+++ b/core/spec/models/spree/price_list_spec.rb@@ -212,6 +212,12 @@ describe Spree::PriceList, type: :model do}.to have_enqueued_job(Spree::Variants::TouchJob).with([product1.master.id])end+ it 'touches the price list to bust cache' do+ expect {+ price_list.add_products([product1.id])+ }.to change { price_list.reload.updated_at }+ end+it 'handles empty product_ids' doexpect {price_list.add_products([])@@ -342,6 +348,12 @@ describe Spree::PriceList, type: :model do}.to have_enqueued_job(Spree::Variants::TouchJob).with([product1.master.id])end+ it 'touches the price list to bust cache' do+ expect {+ price_list.remove_products([product1.id])+ }.to change { price_list.reload.updated_at }+ end+context 'when re-adding a previously removed product' doit 'allows re-adding a product with empty prices' do# Add product, then remove it