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
Rename ProductProperty#param to filter_param
Damian Legawiec8fd61be56c9f
diff --git a/core/app/finders/spree/products/find.rb b/core/app/finders/spree/products/find.rbindex d879fa7462..6c54da673d 100644--- a/core/app/finders/spree/products/find.rb+++ b/core/app/finders/spree/products/find.rb@@ -179,7 +179,7 @@ module Spreeproducts.joins(:product_properties).- where(spree_product_properties: { property_id: property_id, param: values }).ids+ where(spree_product_properties: { property_id: property_id, filter_param: values }).idsend.flatten.compact.uniqproducts.where(id: product_ids)diff --git a/core/app/models/concerns/spree/filter_param.rb b/core/app/models/concerns/spree/filter_param.rbnew file mode 100644index 0000000000..b79eae62a8--- /dev/null+++ b/core/app/models/concerns/spree/filter_param.rb@@ -0,0 +1,21 @@+module Spree+ module FilterParam+ extend ActiveSupport::Concern++ included do+ before_save :set_filter_param+ end++ protected++ def set_filter_param+ return if param_candidate.blank?++ self.filter_param = param_candidate.parameterize+ end++ def param_candidate+ name+ end+ end+enddiff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rbindex 3c0a019f69..cb21b6c27d 100644--- a/core/app/models/spree/product_property.rb+++ b/core/app/models/spree/product_property.rb@@ -1,5 +1,7 @@module Spreeclass ProductProperty < Spree::Base+ include Spree::FilterParam+auto_strip_attributes :valueacts_as_list scope: :product@@ -13,7 +15,7 @@ module Spreedefault_scope { order(:position) }- self.whitelisted_ransackable_attributes = ['value', 'param']+ self.whitelisted_ransackable_attributes = ['value', 'filter_param']self.whitelisted_ransackable_associations = ['property']# virtual attributes for use with AJAX completion stuff@@ -26,10 +28,10 @@ module Spreeendend- def set_param- return if value.blank?+ protected- self.param = value.parameterize+ def param_candidate+ valueendendenddiff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rbindex 879ea24ed5..8bc10b9cf3 100644--- a/core/app/models/spree/property.rb+++ b/core/app/models/spree/property.rb@@ -1,5 +1,7 @@module Spreeclass Property < Spree::Base+ auto_strip_attributes :name+has_many :property_prototypes, class_name: 'Spree::PropertyPrototype'has_many :prototypes, through: :property_prototypes, class_name: 'Spree::Prototype'@@ -16,7 +18,7 @@ module Spreeself.whitelisted_ransackable_attributes = ['presentation']def uniq_values- product_properties.pluck(:param).compact.uniq+ product_properties.pluck(:filter_param).compact.uniqendprivatediff --git a/core/db/migrate/20210504203531_rename_param_to_filter_param_on_spree_product_properties.rb b/core/db/migrate/20210504203531_rename_param_to_filter_param_on_spree_product_properties.rbnew file mode 100644index 0000000000..96cd87b998--- /dev/null+++ b/core/db/migrate/20210504203531_rename_param_to_filter_param_on_spree_product_properties.rb@@ -0,0 +1,5 @@+class RenameParamToFilterParamOnSpreeProductProperties < ActiveRecord::Migration[6.1]+ def change+ rename_column :spree_product_properties, :param, :filter_param+ end+enddiff --git a/core/spec/models/spree/product_property_spec.rb b/core/spec/models/spree/product_property_spec.rbindex e3a650ceb5..0fd12ca7d6 100644--- a/core/spec/models/spree/product_property_spec.rb+++ b/core/spec/models/spree/product_property_spec.rb@@ -27,7 +27,7 @@ describe Spree::ProductProperty, type: :model docontext 'setting param' dosubject { build(:product_property, value: '90% Cotton 10% Elastan') }- it { expect { subject.save! }.to change(subject, :param).from(nil).to('90-cotton-10-elastan') }+ it { expect { subject.save! }.to change(subject, :filter_param).from(nil).to('90-cotton-10-elastan') }endcontext 'setting value' do