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
Touch products on Option Type update (#12174)
Damian Legawiecaac1a0890f99
diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rbindex 5c30754b3c..db3f86f32c 100644--- a/core/app/models/spree/option_type.rb+++ b/core/app/models/spree/option_type.rb@@ -64,6 +64,8 @@ module Spree# Callbacks#after_touch :touch_all_products+ after_update :touch_all_products, if: -> { saved_changes.key?(:presentation) }+ after_destroy :touch_all_products# legacy, name itself is now parameterized before savingdef filter_paramdiff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rbindex 8d790893a2..bda381c88a 100644--- a/core/app/models/spree/option_value.rb+++ b/core/app/models/spree/option_value.rb@@ -56,8 +56,8 @@ module Spree# Callbacks#after_touch :touch_all_variants- after_update :touch_products, if: -> { saved_change_to_presentation? }- after_touch :touch_products+ after_update :touch_all_products, if: -> { saved_changes.key?(:presentation) }+ after_touch :touch_all_productsdelegate :name, :presentation, to: :option_type, prefix: true, allow_nil: true@@ -67,7 +67,7 @@ module Spreevariants.touch_allend- def touch_products+ def touch_all_productsproducts.touch_allendenddiff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rbindex 7ff77a690f..70fce5b865 100644--- a/core/app/models/spree/property.rb+++ b/core/app/models/spree/property.rb@@ -37,6 +37,7 @@ module Spreescope :filterable, -> { where(filterable: true) }after_touch :touch_all_products+ after_update :touch_all_products, if: -> { saved_changes.key?(:presentation) }after_save :ensure_product_properties_have_filter_paramsself.whitelisted_ransackable_attributes = ['presentation', 'filterable']@@ -52,7 +53,7 @@ module Spreeprivatedef touch_all_products- products.update_all(updated_at: Time.current)+ products.touch_allenddef with_uniq_values_cache_key(product_properties_scope, &block)diff --git a/core/spec/models/spree/option_type_spec.rb b/core/spec/models/spree/option_type_spec.rbindex 994932490c..caa4319c57 100644--- a/core/spec/models/spree/option_type_spec.rb+++ b/core/spec/models/spree/option_type_spec.rb@@ -60,13 +60,20 @@ describe Spree::OptionType, type: :model doendcontext 'touching' do- it 'touches a product' do- product_option_type = create(:product_option_type)- option_type = product_option_type.option_type- product = product_option_type.product+ let(:option_type) { create(:option_type) }+ let(:product) { create(:product) }+ let!(:product_option_type) { create(:product_option_type, option_type: option_type, product: product) }++ before doproduct.update_column(:updated_at, 1.day.ago)- option_type.touch- expect(product.reload.updated_at).to be_within(3.seconds).of(Time.current)+ end++ it 'touches a product on touch' do+ expect { option_type.touch }.to change { product.reload.updated_at }+ end++ it 'touches a product on update' do+ expect { option_type.update!(presentation: 'New Presentation') }.to change { product.reload.updated_at }endenddiff --git a/core/spec/models/spree/option_value_spec.rb b/core/spec/models/spree/option_value_spec.rbindex 491f1467b1..ef40231528 100644--- a/core/spec/models/spree/option_value_spec.rb+++ b/core/spec/models/spree/option_value_spec.rb@@ -26,7 +26,7 @@ describe Spree::OptionValue, type: :model doendend- describe '#touch_products' do+ describe '#touch_all_products' dolet!(:option_value) { create(:option_value) }let!(:product1) { create(:product) }let!(:product2) { create(:product) }@@ -39,7 +39,7 @@ describe Spree::OptionValue, type: :model doendit 'touches all products associated with the option value' do- expect { option_value.send(:touch_products) }.to change { [product1.reload.updated_at, product2.reload.updated_at, product3.reload.updated_at] }+ expect { option_value.send(:touch_all_products) }.to change { [product1.reload.updated_at, product2.reload.updated_at, product3.reload.updated_at] }endendend