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.

Set `OptionType#filterable` default value to `true` (#12158)

Damian Legawiec72bdd4b5ecbd
diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rb
index 0bfa05a95e..5c30754b3c 100644
--- a/core/app/models/spree/option_type.rb
+++ b/core/app/models/spree/option_type.rb
@@ -55,8 +55,14 @@ module Spree
scope :search_by_name, ->(query) { where('name LIKE ?', "%#{query}%") }
end
+ #
+ # Attributes
+ #
accepts_nested_attributes_for :option_values, reject_if: ->(ov) { ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true
+ #
+ # Callbacks
+ #
after_touch :touch_all_products
# legacy, name itself is now parameterized before saving
diff --git a/core/db/migrate/20240913143518_change_default_value_of_spree_option_types_filterable.rb b/core/db/migrate/20240913143518_change_default_value_of_spree_option_types_filterable.rb
new file mode 100644
index 0000000000..3265c68170
--- /dev/null
+++ b/core/db/migrate/20240913143518_change_default_value_of_spree_option_types_filterable.rb
@@ -0,0 +1,5 @@
+class ChangeDefaultValueOfSpreeOptionTypesFilterable < ActiveRecord::Migration[6.1]
+ def change
+ change_column_default :spree_option_types, :filterable, from: false, to: true
+ end
+end
diff --git a/core/spec/models/spree/option_type_spec.rb b/core/spec/models/spree/option_type_spec.rb
index 3845c7abd9..994932490c 100644
--- a/core/spec/models/spree/option_type_spec.rb
+++ b/core/spec/models/spree/option_type_spec.rb
@@ -3,6 +3,10 @@ require 'spec_helper'
describe Spree::OptionType, type: :model do
it_behaves_like 'metadata'
+ describe '#filterable' do
+ it { expect(subject.filterable).to eq(true) }
+ end
+
describe 'callbacks' do
describe '#normalize_name' do
let!(:option_type) { build(:option_type, name: 'Shirt Size') }