Skip to content

Instantly share code, notes, and snippets.

@WilliamNHarvey
Created May 29, 2021 21:19
Show Gist options
  • Save WilliamNHarvey/1823b64d794023fddb34933bc7290170 to your computer and use it in GitHub Desktop.
Save WilliamNHarvey/1823b64d794023fddb34933bc7290170 to your computer and use it in GitHub Desktop.
Combine etsy reviews with products to import to shopify
# Update json file names and run with ruby shopifyreviews.rb
require 'json'
require 'date'
# EtsySoldOrderItems csv file, converted to json
order_item_file = File.read('./EtsySoldOrderItems2021.json')
# Reviews file exported from etsy.
# If you have many reviews and you want all of them in shopify, there's some extra work to do here to combine those files.
reviews_file = File.read('./reviews.json')
order_items = JSON.parse(order_item_file)
reviews = JSON.parse(reviews_file)
reviews_length = reviews.length
res = []
reviews.each_with_index do |review, i|
$stdout.flush
print "Percent complete: #{((i + 1).to_f/reviews_length * 100).round(2)}%\r"
order_items.each do |order_item|
# Skip to matching reviews and order items
# Also skip duplicate reviews. I don't know how those get in there on etsy's side but there were thousands.
next if review["order_id"] != order_item["Order ID"] ||
res.find do |hash|
hash[:author] == review["reviewer"] && hash[:product_handle] == order_item["Item Name"]
end != nil
date = Date.strptime(review["date_reviewed"], '%m/%d/%Y')
# This is the format shopify wanted at the time. Make sure to check their template csv for updated column names
obj = {
"product_handle": order_item["Item Name"],
"state": "published",
"rating": review["star_rating"],
"title": "",
"author": review["reviewer"],
"body": review["message"],
"reply": "",
"created_at": date.strftime('%Y-%m-%d'),
"replied_at": ""
}
res.push(obj)
end
end
File.open("reviews_output.json","w") do |f|
f.write(res.to_json)
end
puts "\nOutput written to reviews_output.json"
# Now convert that JSON to a CSV, and do some excel magic to replace your etsy product names with your product path on shopify
# Eg for the product https://shop.thepeachfuzz.co/products/go-low-get-high-refillable-lighter -
# The product_handle should be go-low-get-high-refillable-lighter. You'll have to do this for every shopify product you have, have fun!
# Import this into the Shopify Product Reviews app and you're done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment