Forked from tonkapark/bigcartel_to_shopify_csv.rb
Last active
March 20, 2018 15:26
-
-
Save tomkeysers/f60c24d4dcb9aa97ab68c9da21764887 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 = 'mystorename' | |
# 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 ? 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 ? 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 0..p.images.length-1 do | |
img_row = Shopify.new | |
img_row.handle = p.permalink | |
img_row.image_src = p.images[i].url.sub(".jpg", ".jpg?fit=max&h=2000&w=2000").sub(".JPG", ".JPG?fit=max&h=2000&w=2000").sub(".jpeg", ".jpeg?fit=max&h=2000&w=2000") | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment