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.

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.rb
index d879fa7462..6c54da673d 100644
--- a/core/app/finders/spree/products/find.rb
+++ b/core/app/finders/spree/products/find.rb
@@ -179,7 +179,7 @@ module Spree
products.
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 }).ids
end.flatten.compact.uniq
products.where(id: product_ids)
diff --git a/core/app/models/concerns/spree/filter_param.rb b/core/app/models/concerns/spree/filter_param.rb
new file mode 100644
index 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
+end
diff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rb
index 3c0a019f69..cb21b6c27d 100644
--- a/core/app/models/spree/product_property.rb
+++ b/core/app/models/spree/product_property.rb
@@ -1,5 +1,7 @@
module Spree
class ProductProperty < Spree::Base
+ include Spree::FilterParam
+
auto_strip_attributes :value
acts_as_list scope: :product
@@ -13,7 +15,7 @@ module Spree
default_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 Spree
end
end
- def set_param
- return if value.blank?
+ protected
- self.param = value.parameterize
+ def param_candidate
+ value
end
end
end
diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rb
index 879ea24ed5..8bc10b9cf3 100644
--- a/core/app/models/spree/property.rb
+++ b/core/app/models/spree/property.rb
@@ -1,5 +1,7 @@
module Spree
class 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 Spree
self.whitelisted_ransackable_attributes = ['presentation']
def uniq_values
- product_properties.pluck(:param).compact.uniq
+ product_properties.pluck(:filter_param).compact.uniq
end
private
diff --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.rb
new file mode 100644
index 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
+end
diff --git a/core/spec/models/spree/product_property_spec.rb b/core/spec/models/spree/product_property_spec.rb
index 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 do
context 'setting param' do
subject { 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') }
end
context 'setting value' do