Created
November 30, 2012 22:01
-
-
Save geermc4/4179007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = "" | |
pwd = "" | |
url = 'https://yourstore.com/' | |
login_url = "#{url}login.asp" | |
product_url = "#{url}admin/AdminDetails_Generic.asp?table=Products_Joined&ID=" | |
agent = Mechanize.new | |
page = agent.get(login_url) | |
login_form = page.form('loginform') | |
login_form.email = user | |
login_form.password = pwd | |
login_form.submit | |
Spree::Image.delete_all | |
CSV.foreach("lib/data.csv", :col_sep => ";") do |row| | |
page = agent.get("#{product_url}#{row[0]}") | |
details_form = page.form('EditForm') | |
images = [] | |
`mkdir -p imgs/#{row[0]}` | |
page.search("//img[contains(@class, 'a65chrome_shadow') and contains(@class,'autoheight')]").each do |i| | |
#images have a T in the name for thumbnails, just remove the T and you get full size image. | |
image = File.basename(i['src'].split("?")[0]).gsub("T.",".") | |
next if image == 'no_image.gif' | |
images << image.gsub("T.",".") | |
agent.get( "#{url}#{i['src'].gsub("T.",".")}" ).save "imgs/#{row[0]}/#{image}" | |
end | |
unless row[1].blank? | |
v = Spree::Variant.find_by_sku(row[1]) | |
if v.nil? | |
puts "#{row[1]} not found".red | |
next | |
end | |
v.product.description = details_form['ProductDescription'] | |
v.product.price = details_form['ProductPrice'] | |
v.product.weight = details_form['ProductWeight'] | |
v.product.save! | |
images.each do |i| | |
img = Spree::Image.new(:attachment => File.open("imgs/#{row[0]}/#{i}")) | |
img.save! | |
v.product.images << img | |
end | |
else | |
puts "Missing Spree SKU".red | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment