Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update samples to match new SSF style #5437

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 59 additions & 65 deletions sample/db/samples/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
Spree::Sample.load_sample("variants")

products = {}
products[:solidus_tshirt] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus T-Shirt")
products[:solidus_long] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus Long Sleeve")
products[:solidus_womens_tshirt] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus Women's T-Shirt")
products[:solidus_snapback_cap] = Spree::Product.find_by!(name: "Solidus Snapback Cap")
products[:solidus_hoodie] = Spree::Product.find_by!(name: "Solidus Hoodie Zip")
products[:ruby_hoodie] = Spree::Product.find_by!(name: "Ruby Hoodie")
products[:ruby_hoodie_zip] = Spree::Product.find_by!(name: "Ruby Hoodie Zip")
products[:ruby_polo] = Spree::Product.find_by!(name: "Ruby Polo")
products[:solidus_mug] = Spree::Product.find_by!(name: "Solidus Mug")
products[:ruby_mug] = Spree::Product.find_by!(name: "Ruby Mug")
products[:solidus_tote] = Spree::Product.find_by!(name: "Solidus Tote")
products[:ruby_tote] = Spree::Product.find_by!(name: "Ruby Tote")
products[:solidus_bottles] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus Water Bottle")
products[:solidus_tote] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus tote")
products[:solidus_hoodie] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus hoodie")
products[:solidus_hat] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus winter hat")
products[:solidus_sticker] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus circle sticker")
products[:solidus_cap] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus cap")

image = ->(name, type = "jpg") do
products[:solidus_mug_set] = Spree::Product.find_by!(name: "Solidus mug set")
products[:solidus_notebook] = Spree::Product.find_by!(name: "Solidus notebook")
products[:solidus_tshirt] = Spree::Product.find_by!(name: "Solidus t-shirt")
products[:solidus_long_sleeve_tee] = Spree::Product.find_by!(name: "Solidus long sleeve tee")
products[:solidus_dark_tee] = Spree::Product.find_by!(name: "Solidus dark tee")
products[:solidus_canvas_tote] = Spree::Product.find_by!(name: "Solidus canvas tote bag")
products[:solidus_cap] = Spree::Product.find_by!(name: "Solidus cap")

def image(name, type = "png")
images_path = Pathname.new(File.dirname(__FILE__)) + "images"
path = images_path + "#{name}.#{type}"

Expand All @@ -30,91 +32,83 @@
end

images = {
products[:solidus_snapback_cap].master => [
products[:solidus_bottles].master => [
{
attachment: image("solidus_bottles")
}
],
products[:solidus_tote].master => [
{
attachment: image["solidus_snapback_cap"]
attachment: image("solidus_tote")
}
],
products[:solidus_hoodie].master => [
{
attachment: image["solidus_hoodie"]
attachment: image("solidus_hoodie")
}
],
products[:ruby_hoodie].master => [
products[:solidus_hat].master => [
{
attachment: image["ruby_hoodie"]
attachment: image("solidus_hat")
}
],
products[:ruby_hoodie_zip].master => [
products[:solidus_sticker].master => [
{
attachment: image["ruby_hoodie_zip"]
attachment: image("solidus_sticker")
}
],
products[:ruby_polo].master => [
products[:solidus_mug_set].master => [
{
attachment: image["ruby_polo"]
},
attachment: image("solidus_mug_set")
}
],
products[:solidus_notebook].master => [
{
attachment: image["ruby_polo_back"]
attachment: image("solidus_notebook")
}
],
products[:solidus_mug].master => [
products[:solidus_tshirt].master => [
{
attachment: image["solidus_mug"]
attachment: image("solidus_tshirt")
}
],
products[:ruby_mug].master => [
products[:solidus_long_sleeve_tee].master => [
{
attachment: image["ruby_mug"]
attachment: image("solidus_long_sleeve_tee")
}
],
products[:solidus_tote].master => [
products[:solidus_dark_tee].master => [
{
attachment: image("solidus_dark_tee")
}
],
products[:solidus_canvas_tote].master => [
{
attachment: image["tote_bag_solidus"]
attachment: image("solidus_canvas_tote")
}
],
products[:ruby_tote].master => [
products[:solidus_cap].master => [
{
attachment: image["tote_bag_ruby"]
attachment: image("solidus_cap")
}
]
],
}

products[:solidus_tshirt].variants.each do |variant|
color = variant.option_value("clothing-color").downcase
main_image = image["solidus_tshirt_#{color}", "jpg"]
File.open(main_image) do |f|
variant.images.create!(attachment: f)
end
back_image = image["solidus_tshirt_back_#{color}", "jpg"]

next unless back_image
products.each do |key, product|
product.reload.variants.each do |variant|
color = variant.option_value("clothing-color").downcase
index = 1

File.open(back_image) do |f|
variant.images.create!(attachment: f)
end
end
loop do
image_path = image("#{key}_#{color}_#{index}", 'png')
break unless image_path

products[:solidus_long].variants.each do |variant|
color = variant.option_value("clothing-color").downcase
main_image = image["solidus_long_#{color}", "jpg"]
File.open(main_image) do |f|
variant.images.create!(attachment: f)
end
back_image = image["solidus_long_back_#{color}", "jpg"]
File.open(image_path) do |f|
variant.images.create!(attachment: f)
end

next unless back_image

File.open(back_image) do |f|
variant.images.create!(attachment: f)
end
end

products[:solidus_womens_tshirt].reload.variants.each do |variant|
color = variant.option_value("clothing-color").downcase
main_image = image["solidus_womens_tshirt_#{color}", "jpg"]
File.open(main_image) do |f|
variant.images.create!(attachment: f)
index += 1
end
end
end

Expand Down
Binary file removed sample/db/samples/images/ruby_hoodie.jpg
Binary file not shown.
Binary file removed sample/db/samples/images/ruby_hoodie_zip.jpg
Binary file not shown.
Binary file removed sample/db/samples/images/ruby_mug.jpg
Binary file not shown.
Binary file removed sample/db/samples/images/ruby_polo.jpg
Binary file not shown.
Binary file removed sample/db/samples/images/ruby_polo_back.jpg
Binary file not shown.
Binary file added sample/db/samples/images/solidus_bottles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/db/samples/images/solidus_cap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/db/samples/images/solidus_dark_tee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/db/samples/images/solidus_hat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed sample/db/samples/images/solidus_hoodie.jpg
Binary file not shown.
Binary file added sample/db/samples/images/solidus_hoodie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed sample/db/samples/images/solidus_long.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_long_back.jpg
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_long_black.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_long_blue.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_long_white.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_mug.jpg
Diff not rendered.
Binary file added sample/db/samples/images/solidus_mug_set.png
Binary file added sample/db/samples/images/solidus_notebook.png
Binary file removed sample/db/samples/images/solidus_snapback_cap.jpg
Diff not rendered.
Binary file added sample/db/samples/images/solidus_sticker.png
Binary file added sample/db/samples/images/solidus_tote.png
Binary file removed sample/db/samples/images/solidus_tshirt.jpg
Diff not rendered.
Binary file added sample/db/samples/images/solidus_tshirt.png
Binary file removed sample/db/samples/images/solidus_tshirt_back.jpg
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_tshirt_black.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_tshirt_blue.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_tshirt_white.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/solidus_womens_tshirt.jpg
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed sample/db/samples/images/tote_bag_ruby.jpg
Diff not rendered.
Binary file removed sample/db/samples/images/tote_bag_solidus.jpg
Diff not rendered.
24 changes: 9 additions & 15 deletions sample/db/samples/option_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,15 @@
position: 4,
option_type: size
},
{
name: "Red",
presentation: "Red",
position: 5,
option_type: color
},
{
name: "Green",
presentation: "Green",
position: 4,
option_type: color
},
{
name: "Black",
presentation: "Black",
position: 1,
option_type: color
},
{
name: "White",
presentation: "White",
name: "Gray",
presentation: "Gray",
position: 2,
option_type: color
},
Expand All @@ -59,5 +47,11 @@
presentation: "Blue",
position: 3,
option_type: color
}
},
{
name: "Red",
presentation: "Red",
position: 4,
option_type: color
},
])
8 changes: 4 additions & 4 deletions sample/db/samples/orders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
orders = []
orders << Spree::Order.create!(
number: "R123456789",
email: "solidus@example.com",
email: "spree@example.com",
item_total: 150.95,
adjustment_total: 150.95,
total: 301.90,
Expand All @@ -19,7 +19,7 @@

orders << Spree::Order.create!(
number: "R987654321",
email: "solidus@example.com",
email: "spree@example.com",
item_total: 15.95,
adjustment_total: 15.95,
total: 31.90,
Expand All @@ -28,13 +28,13 @@
)

orders[0].line_items.create!(
variant: Spree::Product.find_by!(name: "Solidus Tote").master,
variant: Spree::Product.find_by!(name: "Solidus Water Bottle").master,
quantity: 1,
price: 15.99
)

orders[1].line_items.create!(
variant: Spree::Product.find_by!(name: "Solidus Snapback Cap").master,
variant: Spree::Product.find_by!(name: "Solidus cap").master,
quantity: 1,
price: 22.99
)
Expand Down
16 changes: 8 additions & 8 deletions sample/db/samples/product_option_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
size = Spree::OptionType.find_by!(presentation: "Size")
color = Spree::OptionType.find_by!(presentation: "Color")

colored_clothes = [
"Solidus T-Shirt", "Solidus Long Sleeve", "Solidus Women's T-Shirt"
]
solidus_cap = Spree::Product.find_by!(name: "Solidus cap")

Spree::Product.all.find_each do |product|
product.option_types = [size]
product.option_types << color if colored_clothes.include?(product.name)
product.save!
end
solidus_cap.option_types = [size, color]
solidus_cap.save!

solidus_hoodie = Spree::Product.find_by!(name: "Solidus hoodie")

solidus_hoodie.option_types = [size, color]
solidus_hoodie.save!
70 changes: 16 additions & 54 deletions sample/db/samples/product_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,110 +2,72 @@

products =
{
"Solidus Tote" =>
"Solidus tote" =>
{
"Type" => "Tote",
"Size" => %{15" x 18" x 6"},
"Material" => "Canvas"
},
"Ruby Tote" =>
"Solidus canvas tote bag" =>
{
"Type" => "Tote",
"Size" => %{15" x 18" x 6"},
"Material" => "Canvas"
},
"Solidus Snapback Cap" =>
"Solidus cap" =>
{
"Type" => "Snapback Cap",
"Type" => "Cap",
"Size" => "One Size",
"Material" => "100% Cotton"
},
"Solidus T-Shirt" =>
"Solidus dark tee" =>
{
"Manufacturer" => "Jerseys",
"Brand" => "Conditioned",
"Brand" => "Solidus",
"Model" => "TL9002",
"Shirt Type" => "Ringer T",
"Sleeve Type" => "Short",
"Made from" => "100% Cotton",
"Fit" => "Loose",
"Gender" => "Men's"
"Gender" => "Unisex"
},
"Solidus Long Sleeve" =>
"Solidus t-shirt" =>
{
"Manufacturer" => "Wilson",
"Brand" => "Wannabe Sports",
"Brand" => "Solidus",
"Model" => "TL9002",
"Shirt Type" => "Jersey",
"Sleeve Type" => "Long",
"Made from" => "100% cotton",
"Fit" => "Loose",
"Gender" => "Men's"
"Gender" => "Unisex"
},
"Solidus Hoodie Zip" =>
"Solidus hoodie" =>
{
"Manufacturer" => "Jerseys",
"Brand" => "Wannabe Sports",
"Brand" => "Solidus",
"Model" => "HD9001",
"Shirt Type" => "Jersey",
"Sleeve Type" => "Long",
"Made from" => "100% cotton",
"Fit" => "Loose",
"Gender" => "Unisex"
},
"Ruby Hoodie" =>
"Solidus long sleeve tee" =>
{
"Manufacturer" => "Wilson",
"Brand" => "Resiliance",
"Brand" => "Solidus",
"Model" => "HD2001",
"Shirt Type" => "Baseball",
"Sleeve Type" => "Long",
"Made from" => "90% Cotton, 10% Nylon",
"Fit" => "Loose",
"Gender" => "Unisex"
},
"Ruby Hoodie Zip" =>
"Solidus Water Bottle" =>
{
"Manufacturer" => "Jerseys",
"Brand" => "Wannabe Sports",
"Model" => "HD9001",
"Shirt Type" => "Jersey",
"Sleeve Type" => "Long",
"Made from" => "100% cotton",
"Fit" => "Loose",
"Gender" => "Unisex"
},
"Ruby Polo" =>
{
"Manufacturer" => "Wilson",
"Brand" => "Resiliance",
"Model" => "PL9001",
"Shirt Type" => "Ringer T",
"Sleeve Type" => "Short",
"Made from" => "100% Cotton",
"Fit" => "Slim",
"Gender" => "Men's"
},
"Solidus Mug" =>
{
"Type" => "Mug",
"Size" => %{4.5" tall, 3.25" dia.}
},
"Ruby Mug" =>
{
"Type" => "Mug",
"Type" => "Insulated Water Bottle",
"Size" => %{4.5" tall, 3.25" dia.}
},
"Solidus Women's T-Shirt" =>
{
"Manufacturer" => "Jerseys",
"Brand" => "Conditioned",
"Model" => "WM6001",
"Shirt Type" => "Skinny",
"Sleeve Type" => "Short",
"Made from" => "90% Cotton, 10% Nylon",
"Fit" => "Slim",
"Gender" => "Women's"
}
}

Expand Down
Loading