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
Replace properties samples with metafields (#13145)
Damian Legawiecd388951b90e1
diff --git a/core/lib/spree/testing_support/store.rb b/core/lib/spree/testing_support/store.rbindex b1ddfe4fd7..649e4d6e0e 100644--- a/core/lib/spree/testing_support/store.rb+++ b/core/lib/spree/testing_support/store.rb@@ -1,5 +1,16 @@# setup default store, to be always presentRSpec.configure do |config|+ config.before(:suite) do+ if defined?(ActiveSupport::SafeBuffer)+ ActiveSupport::SafeBuffer.class_eval do+ # Make Psych serialize SafeBuffer as a plain string+ def encode_with(coder)+ coder.represent_scalar(nil, to_s)+ end+ end+ end+ end+config.before(:all) dounless self.class.metadata[:without_global_store]@default_country = Spree::Country.find_by(iso: 'US') || FactoryBot.create(:country_us)diff --git a/sample/db/samples/metafields.rb b/sample/db/samples/metafields.rbnew file mode 100644index 0000000000..501c25c1da--- /dev/null+++ b/sample/db/samples/metafields.rb@@ -0,0 +1,16 @@+Spree::Sample.load_sample('products')++metafield_values = {+ manufacturer: %w[Wilson Jerseys Wannabe Resiliance Conditioned],+ brand: %w[Alpha Beta Gamma Delta Theta Epsilon Zeta],+ material: ['90% Cotton 10% Elastan', '50% Cotton 50% Elastan', '10% Cotton 90% Elastan'],+ fit: %w[Form Lose]+}++Spree::Product.find_each do |product|+ product.set_metafield('properties.manufacturer', metafield_values[:manufacturer].sample)+ product.set_metafield('properties.brand', metafield_values[:brand].sample)+ product.set_metafield('properties.material', metafield_values[:material].sample)+ product.set_metafield('properties.fit', metafield_values[:fit].sample)+ product.save! if product.changed?+enddiff --git a/sample/db/samples/product_properties.rb b/sample/db/samples/product_properties.rbdeleted file mode 100644index 0ddc73e339..0000000000--- a/sample/db/samples/product_properties.rb+++ /dev/null@@ -1,27 +0,0 @@-Spree::Sample.load_sample('products')--property_values = {- manufacturers: %w[Wilson Jerseys Wannabe Resiliance Conditioned],- brands: %w[Alpha Beta Gamma Delta Theta Epsilon Zeta],- materials: ['90% Cotton 10% Elastan', '50% Cotton 50% Elastan', '10% Cotton 90% Elastan'],- fits: %w[Form Lose]-}--properties = Spree::Property.insert_all([- { name: 'manufacturer', presentation: 'Manufacturer' },- { name: 'brand', presentation: 'Brand' },- { name: 'material', presentation: 'Material' },- { name: 'fit', presentation: 'Fit' },-])--properties_ids = properties.rows.flatten-properties_to_insert = Spree::Product.all.ids.flat_map do |product_id|- [- { product_id: product_id, property_id: properties_ids.first, value: property_values[:manufacturers].sample },- { product_id: product_id, property_id: properties_ids.second, value: property_values[:brands].sample },- { product_id: product_id, property_id: properties_ids.third, value: property_values[:materials].sample },- { product_id: product_id, property_id: properties_ids.fourth, value: property_values[:fits].sample },- ]-end--Spree::ProductProperty.insert_all(properties_to_insert)diff --git a/sample/lib/spree_sample.rb b/sample/lib/spree_sample.rbindex f10d7911ea..efe6670f62 100644--- a/sample/lib/spree_sample.rb+++ b/sample/lib/spree_sample.rb@@ -21,7 +21,7 @@ module SpreeSampleSpree::Sample.load_sample('option_values')Spree::Sample.load_sample('products')Spree::Sample.load_sample('variants')- Spree::Sample.load_sample('product_properties')+ Spree::Sample.load_sample('metafields')Spree::Sample.load_sample('stock')Spree::Sample.load_sample('orders')