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
V-3065 FIX product properties on new product view (#12687)
brozek850811330846
diff --git a/admin/app/helpers/spree/admin/products_helper.rb b/admin/app/helpers/spree/admin/products_helper.rbindex 685c1a60b7..ebdc351d30 100644--- a/admin/app/helpers/spree/admin/products_helper.rb+++ b/admin/app/helpers/spree/admin/products_helper.rb@@ -122,6 +122,10 @@ module Spreedef product_list_filters_search_form_path[:admin, @search]end++ def sorted_product_properties(product)+ product.product_properties.sort_by { |product_property| product_property.property.position }+ endendendenddiff --git a/admin/app/views/spree/admin/products/form/_properties.html.erb b/admin/app/views/spree/admin/products/form/_properties.html.erbindex 46245a1696..fe257d354b 100644--- a/admin/app/views/spree/admin/products/form/_properties.html.erb+++ b/admin/app/views/spree/admin/products/form/_properties.html.erb@@ -15,7 +15,7 @@</tr></thead><tbody>- <%= f.fields_for :product_properties, f.object.product_properties.sort_by_property_position do |product_property_form| %>+ <%= f.fields_for :product_properties, sorted_product_properties(f.object) do |product_property_form| %><% property = product_property_form.object.property %><%= product_property_form.hidden_field :id %><%= product_property_form.hidden_field :property_id %>diff --git a/admin/spec/helpers/spree/admin/products_helper_spec.rb b/admin/spec/helpers/spree/admin/products_helper_spec.rbindex b4e22e73b7..473f30f8c7 100644--- a/admin/spec/helpers/spree/admin/products_helper_spec.rb+++ b/admin/spec/helpers/spree/admin/products_helper_spec.rb@@ -79,4 +79,23 @@ describe Spree::Admin::ProductsHelper doendendend++ describe '#sorted_product_properties' do+ let(:product) { create(:product) }++ context 'when the product has product properties' do+ let!(:product_property1) { create(:product_property, product: product, property: create(:property, position: 2)) }+ let!(:product_property2) { create(:product_property, product: product, property: create(:property, position: 1)) }++ it 'returns the product properties sorted by position' do+ expect(sorted_product_properties(product)).to eq([product_property2, product_property1])+ end+ end++ context 'when the product has no product properties' do+ it 'returns an empty array' do+ expect(sorted_product_properties(product)).to eq([])+ end+ end+ endend