Skip to content

Instantly share code, notes, and snippets.

@juque
Created June 29, 2021 08:10
Show Gist options
  • Select an option

  • Save juque/7ff26e21172196695ec1897ceadd83eb to your computer and use it in GitHub Desktop.

Select an option

Save juque/7ff26e21172196695ec1897ceadd83eb to your computer and use it in GitHub Desktop.
shop = root.shops.first
products = shop.products(collections: "deals", class: "product").full_set
file = 'backup_variants_deals.csv'
columns = ["sku", "regular_price", "sale_price"]
data = CSV.generate do |csv|
csv << columns
products.each do |product|
variants = product.variants
variants.each do |variant|
csv << [variant.sku, variant.regular_price, variant.sale_price]
end
end
end
File.write(file, data)
puts "#{file} <-- OK!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment