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
Speed up loading samples
Damian Legawiecce68e6d9cc2b
diff --git a/sample/db/samples/data_feeds.rb b/sample/db/samples/data_feeds.rbdeleted file mode 100644index 8e25bbef3a..0000000000--- a/sample/db/samples/data_feeds.rb+++ /dev/null@@ -1,6 +0,0 @@-# settings for default store-Spree::DataFeed::Google.create!(- store: Spree::Store.default,- name: 'Default Google Data Feed'-)-diff --git a/sample/db/samples/product_properties.rb b/sample/db/samples/product_properties.rbindex 4b2695cebd..0ddc73e339 100644--- a/sample/db/samples/product_properties.rb+++ b/sample/db/samples/product_properties.rb@@ -1,102 +1,27 @@-Spree::Sample.load_sample('taxons')Spree::Sample.load_sample('products')-men_tshirts_properties = [- {- 'manufacturer' => 'Wilson',- 'brand' => 'Wannabe Sports',- 'model' => 'JK1002',- 'shirt_type' => 'Baseball Jersey',- 'sleeve_type' => 'Long',- 'material' => '100% cotton',- 'fit' => 'Loose',- 'gender' => 'Men\'s'- },- {- 'manufacturer' => 'Jerseys',- 'brand' => 'Conditioned',- 'model' => 'TL9002',- 'shirt_type' => 'Ringer T',- 'sleeve_type' => 'Short',- 'material' => '100% Vellum',- 'fit' => 'Loose',- 'gender' => 'Men\'s'- },- {- 'manufacturer' => 'Wilson',- 'brand' => 'Wannabe Sports',- 'model' => 'JK1002',- 'shirt_type' => 'Baseball Jersey',- 'sleeve_type' => 'Long',- 'material' => '100% cotton',- 'fit' => 'Loose',- 'gender' => 'Men\'s'- },- {- 'manufacturer' => 'Jerseys',- 'brand' => 'Conditioned',- 'model' => 'TL9002',- 'shirt_type' => 'Ringer T',- 'sleeve_type' => 'Short',- 'material' => '100% Vellum',- 'fit' => 'Loose',- 'gender' => 'Men\'s'- }-]-Spree::Taxon.find_by!(name: 'Men').children.find_by!(name: 'T-shirts').products.each do |product|- men_tshirts_properties.sample.each do |prop_name, prop_value|- product.set_property(prop_name, prop_value, prop_name.gsub('_', ' ').capitalize)- end-end--women_tshirts_properties = [- {- 'manufacturer' => 'Jerseys',- 'brand' => 'Resiliance',- 'model' => 'TL174',- 'shirt_type' => 'Jr. Spaghetti T',- 'sleeve_type' => 'None',- 'material' => '90% Cotton, 10% Nylon',- 'fit' => 'Form',- 'gender' => 'Women\'s'- },- {- 'manufacturer' => 'Jerseys',- 'brand' => 'Resiliance',- 'model' => 'TL174',- 'shirt_type' => 'Jr. Spaghetti T',- 'sleeve_type' => 'None',- 'material' => '90% Cotton, 10% Nylon',- 'fit' => 'Form',- 'gender' => 'Women\'s'- }-]--Spree::Taxon.find_by!(name: 'Women').children.find_by!(name: 'Tops and T-shirts').products.each do |product|- women_tshirts_properties.sample.each do |prop_name, prop_value|- product.set_property(prop_name, prop_value, prop_name.gsub('_', ' ').capitalize)- end-end--properties = {+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]}-t_shirts_taxon = Spree::Taxon.where(name: ['T-shirts', 'Tops and T-shirts'])--Spree::Product.all.each do |product|- product.set_property(:type, product.taxons.first.name)- product.set_property(:collection, product.taxons.first.name)-- next if product.taxons.include?(t_shirts_taxon)-- product.set_property(:manufacturer, properties[:manufacturers].sample)- product.set_property(:brand, properties[:brands].sample)- product.set_property(:material, properties[:materials].sample)- product.set_property(:fit, properties[:fits].sample)- product.set_property(:gender, (product.taxons.pluck(:name).include?('Men') ? 'Men\'s' : 'Women\'s'))- product.set_property(:model, product.sku)+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/db/samples/products.rb b/sample/db/samples/products.rbindex 671f446fd1..36fac281d2 100644--- a/sample/db/samples/products.rb+++ b/sample/db/samples/products.rb@@ -16,12 +16,14 @@ PRODUCTS = CSV.read(File.join(__dir__, 'variants.csv')).map do |(parent_name, ta[parent_name, taxon_name, product_name]end.uniq+taxons = Spree::Taxon.includes(:children).all+stores = Spree::Store.all+PRODUCTS.each do |(parent_name, taxon_name, product_name)|- parent = Spree::Taxon.find_by!(name: parent_name)- taxon = parent.children.find_by!(name: taxon_name)- next if Spree::Product.where(name: product_name.titleize).any?+ parent = taxons.find { |taxon| taxon.name == parent_name }+ taxon = parent.children.find { |child| child.name == taxon_name }- Spree::Product.create!(name: product_name.titleize) do |product|+ Spree::Product.create(name: product_name.titleize) do |product|product.price = rand(10...100) + 0.99product.description = FFaker::Lorem.paragraphproduct.available_on = Time.zone.now@@ -38,12 +40,6 @@ PRODUCTS.each do |(parent_name, taxon_name, product_name)|product.sku = [taxon_name.delete(' '), product_name.delete(' '), product.price].join('_')product.taxons << parent unless product.taxons.include?(parent)product.taxons << taxon unless product.taxons.include?(taxon)- product.stores = Spree::Store.all+ product.stores = storesendend--Spree::Taxon.where(name: ['Bestsellers', 'New', 'Trending', 'Streetstyle', 'Summer Sale', "Summer #{Date.today.year}", '30% Off']).each do |taxon|- next if taxon.products.any?-- taxon.products << Spree::Product.all.sample(30)-enddiff --git a/sample/db/samples/properties.rb b/sample/db/samples/properties.rbdeleted file mode 100644index 9d8ad97e69..0000000000--- a/sample/db/samples/properties.rb+++ /dev/null@@ -1,22 +0,0 @@-properties = {- brand: 'Brand',- model: 'Model',- manufacturer: 'Manufacturer',- made_from: 'Made from',- fit: 'Fit',- gender: 'Gender',- type: 'Type',- size: 'Size',- material: 'Material',- length: 'Lenght',- color: 'Color',- collection: 'Collection'-}--properties_data = properties.map do |name, presentation|- { name: name, presentation: presentation }-end--Spree::Property.insert_all(properties_data)--Spree::Property.where(name: %w[brand manufacturer]).update(filterable: true)diff --git a/sample/db/samples/variants.rb b/sample/db/samples/variants.rbindex f5788f8cbe..8517ee510b 100644--- a/sample/db/samples/variants.rb+++ b/sample/db/samples/variants.rb@@ -11,11 +11,14 @@ color_option_values = Spree::OptionType.find_by!(name: 'color').option_valueslength_option_values = Spree::OptionType.find_by!(name: 'length').option_valuessize_option_values = Spree::OptionType.find_by!(name: 'size').option_values+taxons = Spree::Taxon.includes(:children).all+products = Spree::Product.all+VARIANTS.each do |(parent_name, taxon_name, product_name, color_name)|- parent = Spree::Taxon.find_by!(name: parent_name)- taxon = parent.children.find_by!(name: taxon_name)- product = Spree::Product.find_by!(name: product_name.titleize)- color = color_option_values.find_by!(name: color_name)+ parent = taxons.find { |t| t.name == parent_name }+ taxon = taxons.find { |t| t.parent_id == parent.id && t.name == taxon_name }+ product = products.find { |p| p.name == product_name.titleize }+ color = color_option_values.find { |c| c.name == color_name }size_option_values.each do |size|if parent_name == 'Women' and %w[Dresses Skirts].include?(taxon_name)diff --git a/sample/lib/spree_sample.rb b/sample/lib/spree_sample.rbindex 26bcbd3350..6fb15abb21 100644--- a/sample/lib/spree_sample.rb+++ b/sample/lib/spree_sample.rb@@ -30,7 +30,6 @@ module SpreeSampleSpree::Sample.load_sample('reimbursements')Spree::Sample.load_sample('return_authorization_reasons')Spree::Sample.load_sample('stores')- Spree::Sample.load_sample('data_feeds')endendend