Skip to content

Commit

Permalink
Merge pull request #3389 from JDutil/fix-2978
Browse files Browse the repository at this point in the history
Reload product before assigning images to variants
  • Loading branch information
kennyadsl committed Oct 26, 2019
2 parents 95ae9b9 + 8fe2776 commit a591fdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 10 additions & 4 deletions sample/db/samples/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
Spree::Sample.load_sample("variants")

products = {}
products[:solidus_tshirt] = Spree::Product.find_by!(name: "Solidus T-Shirt")
products[:solidus_long] = Spree::Product.find_by!(name: "Solidus Long Sleeve")
products[:solidus_girly] = Spree::Product.find_by!(name: "Solidus Girly")
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_girly] = Spree::Product.includes(variants: [:option_values]).find_by!(name: "Solidus Girly")
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")
Expand All @@ -20,7 +20,9 @@
def image(name, type = "jpg")
images_path = Pathname.new(File.dirname(__FILE__)) + "images"
path = images_path + "#{name}.#{type}"

return false if !File.exist?(path)

path
end

Expand Down Expand Up @@ -103,7 +105,9 @@ def image(name, type = "jpg")
variant.images.create!(attachment: f)
end
back_image = image("solidus_tshirt_back_#{color}", "png")

next unless back_image

File.open(back_image) do |f|
variant.images.create!(attachment: f)
end
Expand All @@ -116,13 +120,15 @@ def image(name, type = "jpg")
variant.images.create!(attachment: f)
end
back_image = image("solidus_long_back_#{color}", "png")

next unless back_image

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

products[:solidus_girly].variants.each do |variant|
products[:solidus_girly].reload.variants.each do |variant|
color = variant.option_value("tshirt-color").downcase
main_image = image("solidus_girly_#{color}", "png")
File.open(main_image) do |f|
Expand Down
2 changes: 0 additions & 2 deletions sample/db/samples/variants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
large = Spree::OptionValue.find_by!(name: "Large")
extra_large = Spree::OptionValue.find_by!(name: "Extra Large")

red = Spree::OptionValue.find_by!(name: "Red")
blue = Spree::OptionValue.find_by!(name: "Blue")
green = Spree::OptionValue.find_by!(name: "Green")
black = Spree::OptionValue.find_by!(name: "Black")
white = Spree::OptionValue.find_by!(name: "White")

Expand Down

0 comments on commit a591fdf

Please sign in to comment.