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.

Admin: Fixed rendering and setting properties for product form (#12931)

Damian Legawiecd77059458d66
diff --git a/admin/app/helpers/spree/admin/products_helper.rb b/admin/app/helpers/spree/admin/products_helper.rb
index eae5f696c6..ebdc351d30 100644
--- a/admin/app/helpers/spree/admin/products_helper.rb
+++ b/admin/app/helpers/spree/admin/products_helper.rb
@@ -124,7 +124,7 @@ module Spree
end
def sorted_product_properties(product)
- product.product_properties.includes(:property).sort_by { |product_property| product_property.property.position }
+ product.product_properties.sort_by { |product_property| product_property.property.position }
end
end
end
diff --git a/admin/spec/features/spree/admin/products/edit/properties_spec.rb b/admin/spec/features/spree/admin/products/edit/properties_spec.rb
new file mode 100644
index 0000000000..5e9c59786d
--- /dev/null
+++ b/admin/spec/features/spree/admin/products/edit/properties_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+describe 'Product Properties', type: :feature, js: true do
+ stub_authorization!
+
+ let(:store) { Spree::Store.default }
+ let(:product) { create(:product, stores: [store]) }
+
+ let!(:brand_property) { create(:property, name: 'brand', presentation: 'Brand', position: 1) }
+ let!(:material_property) { create(:property, name: 'material', presentation: 'Material', position: 2) }
+
+ before do
+ product.set_property('brand', 'Epsilon')
+ end
+
+ it 'shows associated properties in the form plus a new property' do
+ visit spree.edit_admin_product_path(product)
+ expect(page).to have_content('brand')
+ expect(page).to have_field('product_product_properties_attributes_0_value', with: 'Epsilon')
+ expect(page).to have_content('material')
+ expect(page).to have_field('product_product_properties_attributes_1_value', with: '')
+
+ fill_in 'product_product_properties_attributes_1_value', with: 'Cotton'
+ within('#page-header') { click_button 'Update' }
+
+ expect(page).to have_content('successfully updated!')
+
+ expect(product.reload.property('material')).to eq('Cotton')
+ expect(product.property('brand')).to eq('Epsilon')
+
+ expect(page).to have_field('product_product_properties_attributes_0_value', with: 'Epsilon')
+ expect(page).to have_field('product_product_properties_attributes_1_value', with: 'Cotton')
+ end
+end