Created
August 3, 2011 18:06
-
-
Save tonkapark/1123342 to your computer and use it in GitHub Desktop.
Generate a products csv file to make it easier to migrate from Big Cartel to Shopify
This file contains hidden or 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
#script created by Matt Anderson, http://tonkapark.com | |
require 'rubygems' | |
require 'bigcartel' | |
require 'csv' | |
# SET YOUR BIGCARTEL ID HERE | |
STORE = 'ugmonk' | |
# SET THE BEST NAME FOR ANY DROP DOWN OPTIONS | |
BC_OPTION_NAME = "Size" | |
class Shopify < | |
Struct.new(:handle, :title, :body,:vendor,:type,:tags, | |
:opt1_name, :opt1_val, | |
:opt2_name, :opt2_val, | |
:opt3_name, :op3_val, | |
:sku,:grams,:inventory_tracker,:qty, :inventory_policy, :fullfillment, | |
:price,:compare_at, :requires_shipping, :taxable, :image_src) | |
end | |
s = BigCartel.store(STORE) | |
rows = Array.new | |
s.products.each do |p| | |
row = Shopify.new | |
row.handle = p.permalink | |
row.title = p.name | |
row.body = p.description | |
row.vendor = s.name | |
row.type = p.categories.first.name | |
row.tags = p.categories.collect{|x| x.name}.join(', ') | |
if p.has_default_option | |
row.opt1_name = BC_OPTION_NAME | |
row.opt1_val = p.option.name | |
price = p.option.price | |
else | |
row.opt1_name = BC_OPTION_NAME | |
row.opt1_val = p.options.first.name | |
price = p.options.first.price | |
end | |
row.price = price | |
row.image_src = p.image.url | |
#defaults to allow import to shopify | |
row.qty = 0 | |
row.inventory_policy = 'deny' | |
row.fullfillment = 'manual' | |
row.sku = p.id | |
rows.push(row) | |
#additional variants | |
unless p.has_default_option | |
for i in 1..p.options.length-1 do | |
opt_row = Shopify.new | |
opt_row.handle = p.permalink | |
opt_row.opt1_name = BC_OPTION_NAME | |
opt_row.opt1_val = p.options[i].name | |
opt_row.price = p.options[i].price | |
#defaults to allow import to shopify | |
opt_row.qty = 0 | |
opt_row.inventory_policy = 'deny' | |
opt_row.fullfillment = 'manual' | |
opt_row.sku = p.id | |
rows.push(opt_row) | |
end | |
end | |
#additional images | |
for i in 1..p.images.length-1 do | |
img_row = Shopify.new | |
img_row.handle = p.permalink | |
img_row.image_src = p.images[i].url | |
rows.push(img_row) | |
end | |
end | |
file_name = "#{STORE}.csv" | |
CSV.open(file_name, 'w') do |csv| | |
header_row = ["Handle", "Title", "Body (HTML)", "Vendor", "Type", "Tags", "Option1 Name", "Option1 Value", "Option2 Name", "Option2 Value", "Option3 Name", "Option3 Value", "Variant SKU", "Variant Grams", "Variant Inventory Tracker", "Variant Inventory Qty", "Variant Inventory Policy", "Variant Fulfillment Service", "Variant Price", "Variant Compare At Price", "Variant Requires Shipping", "Variant Taxable", "Image Src"] | |
csv << header_row | |
rows.each { |p| | |
csv << p | |
} | |
end |
I get the following error:
Conn close
Traceback (most recent call last):
2: from ../1123342/bigcartel_to_shopify_csv.rb:26:in <main>' 1: from ../1123342/bigcartel_to_shopify_csv.rb:26:in
each'
../1123342/bigcartel_to_shopify_csv.rb:47:in block in <main>': undefined method
url' for nil:NilClass (NoMethodError)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried running this but I get an error:
bigcartel_to_shopify_csv.rb:26:in
<main>': undefined method
each' for nil:NilClass (NoMethodError)Looks like it's parsing the data though, just stopping before the csv file is created.