From 9eda486ef6821034f6957802c7473ff672aba51a Mon Sep 17 00:00:00 2001 From: Paulo DAlberti Date: Thu, 20 Oct 2022 15:04:49 +0900 Subject: [PATCH] Assign option types to all clothing samples It is unexpected that the loading of samples only provides size and colour options to Solidus T-Shirt. This commit creates `Spree::ProductOptionType`s for all clothing options and adds size variants for the clothes which were missing any. It also updates the names of the generated `Spree::OptionType`s to match the ones from demo.solidus.io. --- sample/db/samples/assets.rb | 6 +- sample/db/samples/option_types.rb | 4 +- sample/db/samples/product_option_types.rb | 23 +++++- sample/db/samples/variants.rb | 90 +++++++++++++++++++++++ 4 files changed, 115 insertions(+), 8 deletions(-) diff --git a/sample/db/samples/assets.rb b/sample/db/samples/assets.rb index 5e3dc019403..25c87eaeb47 100644 --- a/sample/db/samples/assets.rb +++ b/sample/db/samples/assets.rb @@ -81,7 +81,7 @@ } products[:solidus_tshirt].variants.each do |variant| - color = variant.option_value("tshirt-color").downcase + color = variant.option_value("clothing-color").downcase main_image = image["solidus_tshirt_#{color}", "png"] File.open(main_image) do |f| variant.images.create!(attachment: f) @@ -96,7 +96,7 @@ end products[:solidus_long].variants.each do |variant| - color = variant.option_value("tshirt-color").downcase + color = variant.option_value("clothing-color").downcase main_image = image["solidus_long_#{color}", "png"] File.open(main_image) do |f| variant.images.create!(attachment: f) @@ -111,7 +111,7 @@ end products[:solidus_womens_tshirt].reload.variants.each do |variant| - color = variant.option_value("tshirt-color").downcase + color = variant.option_value("clothing-color").downcase main_image = image["solidus_womens_tshirt_#{color}", "png"] File.open(main_image) do |f| variant.images.create!(attachment: f) diff --git a/sample/db/samples/option_types.rb b/sample/db/samples/option_types.rb index 113e37e9a51..5f2935384d9 100644 --- a/sample/db/samples/option_types.rb +++ b/sample/db/samples/option_types.rb @@ -2,12 +2,12 @@ Spree::OptionType.create!([ { - name: "tshirt-size", + name: "clothing-size", presentation: "Size", position: 1 }, { - name: "tshirt-color", + name: "clothing-color", presentation: "Color", position: 2 } diff --git a/sample/db/samples/product_option_types.rb b/sample/db/samples/product_option_types.rb index 66aa29bb153..45d51fe304c 100644 --- a/sample/db/samples/product_option_types.rb +++ b/sample/db/samples/product_option_types.rb @@ -5,6 +5,23 @@ size = Spree::OptionType.find_by!(presentation: "Size") color = Spree::OptionType.find_by!(presentation: "Color") -solidus_tshirt = Spree::Product.find_by!(name: "Solidus T-Shirt") -solidus_tshirt.option_types = [size, color] -solidus_tshirt.save! +sized_and_colored_clothes = Spree::Product.where( + name: [ + "Solidus T-Shirt", "Solidus Long Sleeve", "Solidus Women's T-Shirt" + ] +) +sized_and_colored_clothes.each do |product| + product.option_types = [size, color] + product.save! +end + +sized_clothes = Spree::Product.where( + name: [ + "Solidus Snapback Cap", "Solidus Hoodie Zip", "Ruby Hoodie", + "Ruby Hoodie Zip", "Ruby Polo" + ] +) +sized_clothes.each do |product| + product.option_types = [size] + product.save! +end diff --git a/sample/db/samples/variants.rb b/sample/db/samples/variants.rb index 248edf5b066..9da88b04654 100644 --- a/sample/db/samples/variants.rb +++ b/sample/db/samples/variants.rb @@ -157,6 +157,96 @@ option_values: [medium, black], sku: "SOL-WM006", cost_price: 17 + }, + { + product: solidus_snapback_cap, + option_values: [small], + sku: "SOL-SNC02", + cost_price: 17 + }, + { + product: solidus_snapback_cap, + option_values: [medium], + sku: "SOL-SNC03", + cost_price: 17 + }, + { + product: solidus_snapback_cap, + option_values: [large], + sku: "SOL-SNC04", + cost_price: 17 + }, + { + product: solidus_hoodie, + option_values: [small], + sku: "SOL-HD02", + cost_price: 27 + }, + { + product: solidus_hoodie, + option_values: [medium], + sku: "SOL-HD03", + cost_price: 27 + }, + { + product: solidus_hoodie, + option_values: [large], + sku: "SOL-HD04", + cost_price: 27 + }, + { + product: ruby_hoodie, + option_values: [small], + sku: "RUB-HD02", + cost_price: 27 + }, + { + product: ruby_hoodie, + option_values: [medium], + sku: "RUB-HD03", + cost_price: 27 + }, + { + product: ruby_hoodie, + option_values: [large], + sku: "RUB-HD04", + cost_price: 27 + }, + { + product: ruby_hoodie_zip, + option_values: [small], + sku: "RUB-HD05", + cost_price: 27 + }, + { + product: ruby_hoodie_zip, + option_values: [medium], + sku: "RUB-HD06", + cost_price: 27 + }, + { + product: ruby_hoodie_zip, + option_values: [large], + sku: "RUB-HD07", + cost_price: 27 + }, + { + product: ruby_polo, + option_values: [small], + sku: "RUB-PL02", + cost_price: 23 + }, + { + product: ruby_polo, + option_values: [medium], + sku: "RUB-PL03", + cost_price: 23 + }, + { + product: ruby_polo, + option_values: [large], + sku: "RUB-PL04", + cost_price: 23 } ]