Skip to content

Commit

Permalink
Assign option types to all clothing samples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Naokimi committed Oct 20, 2022
1 parent 5f628dd commit 9eda486
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sample/db/samples/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions sample/db/samples/option_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 20 additions & 3 deletions sample/db/samples/product_option_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
90 changes: 90 additions & 0 deletions sample/db/samples/variants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]

Expand Down

0 comments on commit 9eda486

Please sign in to comment.