One problem: The Magento installation had 9000 products, with names, descriptions, SKUs, and other fun attributes. Spree has no built-in import or export function. Do I want to enter all this information manually? No.
After some googling, yahooing, and asking jeeves, I found a Google group discussion, took some of the example code, tailored it to the CSV format of a standard Magento export, and ended up with this hack:
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
require 'fastercsv' | |
n = 0 | |
FasterCSV.foreach("export_all_products.csv") do |row| | |
if n != 0 | |
puts "Adding new product: #{row[7]}" | |
product = Product.new | |
product.name = row[7] | |
product.description = row[27] | |
product.sku = row[5].to_s | |
product.price = row[22].to_d | |
product.save! | |
end | |
n += 1 | |
end | |
puts "" | |
puts "Import Completed - Added: #{n} Products" |
gem install fastercsv
Use the Rails runner to run this script so it has access to the database:
script/runner import.rb
and you're done.
Thanks for posting this. I'm hoping to convince my boss in a few months to let me switch our massive store (29k SKUs) from Magento to Spree. This was a hurdle I wasn't looking forward to dealing with.
ReplyDeleteNo problem, glad I was able to help someone out!
ReplyDeleteGood to know, FasterCSV looks useful. I'm trying to do the same thing but decided to go with datashift_spree. It supports importing images and it allows you set default values if some of the columns are missing. All from the command line.
ReplyDeletehttps://github.com/autotelik/datashift_spree