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.

Add `kind` to `Property`

Damian Legawiec937bd10bdee9
diff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rb
index ba5f03559f..4fc689e991 100644
--- a/core/app/models/spree/product_property.rb
+++ b/core/app/models/spree/product_property.rb
@@ -32,6 +32,9 @@ module Spree
scope :filterable, -> { joins(:property).where(Property.table_name => { filterable: true }) }
scope :for_products, ->(products) { joins(:product).merge(products) }
+ scope :sort_by_property_position, -> {
+ joins(:property).order("spree_properties.position ASC")
+ }
self.whitelisted_ransackable_attributes = ['value', 'filter_param']
self.whitelisted_ransackable_associations = ['property']
diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rb
index ec8b70e3b8..47efa317f0 100644
--- a/core/app/models/spree/property.rb
+++ b/core/app/models/spree/property.rb
@@ -36,6 +36,13 @@ module Spree
scope :sorted, -> { order(:name) }
scope :filterable, -> { where(filterable: true) }
+ KIND_OPTIONS = { short_text: 0, long_text: 1, number: 2, rich_text: 3 }.freeze
+ if Rails.version >= '7.0'
+ enum :kind, KIND_OPTIONS
+ else
+ enum kind: KIND_OPTIONS
+ end
+
after_touch :touch_all_products
after_update :touch_all_products, if: -> { saved_changes.key?(:presentation) }
after_save :ensure_product_properties_have_filter_params
diff --git a/core/db/migrate/20250127083740_add_kind_to_spree_properties.rb b/core/db/migrate/20250127083740_add_kind_to_spree_properties.rb
new file mode 100644
index 0000000000..e9bc5750f4
--- /dev/null
+++ b/core/db/migrate/20250127083740_add_kind_to_spree_properties.rb
@@ -0,0 +1,5 @@
+class AddKindToSpreeProperties < ActiveRecord::Migration[6.1]
+ def change
+ add_column :spree_properties, :kind, :integer, default: 0, if_not_exists: true
+ end
+end