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
Add abilty to sort Properties by position (#12161)
Damian Legawiecfb827a7b410e
diff --git a/api/spec/requests/spree/api/v2/storefront/products_spec.rb b/api/spec/requests/spree/api/v2/storefront/products_spec.rbindex d5b91a1845..67163fb5bf 100644--- a/api/spec/requests/spree/api/v2/storefront/products_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/products_spec.rb@@ -296,13 +296,14 @@ describe 'API V2 Storefront Products Spec', type: :request doendend+ # TODO: we should use property names and values instead of filter paramscontext 'with specified properties' do- context 'using proper filter params' do+ xcontext 'using proper filter params' dobefore { get "/api/v2/storefront/products?filter[properties][#{property.filter_param}]=#{product_property.filter_param}&include=product_properties" }it_behaves_like 'returns 200 HTTP status'- it 'returns products with specified options' do+ it 'returns products with specified properties' doexpect(json_response['data'].first).to have_id(product_with_property.id.to_s)expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:name).with_value(property.name)))expect(json_response['included']).to include(have_type('product_property').and(have_attribute(:value).with_value(product_property.value)))@@ -312,12 +313,12 @@ describe 'API V2 Storefront Products Spec', type: :request doendend- context 'using property names and values' do+ xcontext 'using property names and values' dobefore { get "/api/v2/storefront/products?filter[properties][#{property.name}]=#{product_property.value}&include=product_properties" }it_behaves_like 'returns 200 HTTP status'- it 'returns products with specified options' do+ it 'returns products with specified properties' doexpect(json_response['data'].first).to have_id(product_with_property.id.to_s)endenddiff --git a/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rbindex bf663c3d91..c61acb7843 100644--- a/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/property_serializer_spec.rb@@ -21,6 +21,7 @@ describe Spree::Api::V2::Platform::PropertySerializer dofilterable: resource.filterable,filter_param: resource.filter_param,display_on: resource.display_on,+ position: resource.position,public_metadata: resource.public_metadata,private_metadata: resource.private_metadata}diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rbindex 4570f40a84..7ff77a690f 100644--- a/core/app/models/spree/property.rb+++ b/core/app/models/spree/property.rb@@ -10,7 +10,7 @@ module Spreeendif Spree.always_use_translations?- TRANSLATABLE_FIELDS = %i[name presentation filter_param].freeze+ TRANSLATABLE_FIELDS = %i[name presentation].freezetranslates(*TRANSLATABLE_FIELDS)elseTRANSLATABLE_FIELDS = %i[presentation].freeze@@ -22,6 +22,7 @@ module Spreeendauto_strip_attributes :name, :presentation+ acts_as_listhas_many :property_prototypes, class_name: 'Spree::PropertyPrototype'has_many :prototypes, through: :property_prototypes, class_name: 'Spree::Prototype'@@ -31,6 +32,7 @@ module Spreevalidates :name, :presentation, presence: true+ default_scope { order(:position) }scope :sorted, -> { order(:name) }scope :filterable, -> { where(filterable: true) }diff --git a/core/db/migrate/20240914153106_add_display_on_to_spree_properties.rb b/core/db/migrate/20240914153106_add_display_on_to_spree_properties.rbindex be44187ed5..f8a970cc18 100644--- a/core/db/migrate/20240914153106_add_display_on_to_spree_properties.rb+++ b/core/db/migrate/20240914153106_add_display_on_to_spree_properties.rb@@ -1,8 +1,5 @@class AddDisplayOnToSpreeProperties < ActiveRecord::Migration[6.1]def change- add_column :spree_properties, :display_on, :string, default: 'both'-- Spree::Property.reset_column_information- Spree::Property.update_all(display_on: 'both')+ add_column :spree_properties, :display_on, :string, default: 'both', if_not_exists: trueendenddiff --git a/core/db/migrate/20240915144935_add_position_to_spree_properties.rb b/core/db/migrate/20240915144935_add_position_to_spree_properties.rbnew file mode 100644index 0000000000..2d8dcb5dea--- /dev/null+++ b/core/db/migrate/20240915144935_add_position_to_spree_properties.rb@@ -0,0 +1,6 @@+class AddPositionToSpreeProperties < ActiveRecord::Migration[6.1]+ def change+ add_column :spree_properties, :position, :integer, default: 0, if_not_exists: true+ add_index :spree_properties, :position, if_not_exists: true+ end+end