|
20 | 20 | PRODUCTS.each do |(parent_name, taxon_name, product_name)|
|
21 | 21 | parent = Spree::Taxon.find_by!(name: parent_name)
|
22 | 22 | taxon = parent.children.find_by!(name: taxon_name)
|
23 |
| - taxon.products.where(name: product_name.titleize).first_or_create! do |product| |
| 23 | + Spree::Product.where(name: product_name.titleize).first_or_create! do |product| |
24 | 24 | product.price = rand(10...100) + 0.99
|
25 | 25 | product.description = FFaker::Lorem.paragraph
|
26 | 26 | product.available_on = Time.zone.now
|
27 | 27 | product.option_types = [color, size]
|
28 | 28 | product.shipping_category = default_shipping_category
|
29 | 29 | product.tax_category = clothing_tax_category
|
30 | 30 | product.sku = [taxon_name.delete(' '), product_name.delete(' '), product.price].join('_')
|
31 |
| - parent.products << product |
| 31 | + product.taxons << parent unless product.taxons.include?(parent) |
| 32 | + product.taxons << taxon unless product.taxons.include?(taxon) |
32 | 33 | end
|
33 | 34 | end
|
34 | 35 |
|
35 |
| -['Bestsellers', 'New', 'Trending', 'Streetstyle', 'Summer Sale'].each do |taxon_name| |
36 |
| - Spree::Taxon.find_by!(name: taxon_name).products << Spree::Product.all.sample(30) |
| 36 | +Spree::Taxon.where(name: ['Bestsellers', 'New', 'Trending', 'Streetstyle', 'Summer Sale']).each do |taxon| |
| 37 | + next if taxon.products.any? |
| 38 | + |
| 39 | + taxon.products << Spree::Product.all.sample(30) |
37 | 40 | end
|
0 commit comments