Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schappim/c73990935b750401781519d3bcaeb328 to your computer and use it in GitHub Desktop.
Save schappim/c73990935b750401781519d3bcaeb328 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'csv'
response = HTTParty.get 'https://docs.google.com/spreadsheets/d/1lN8dXM9y-8GwXsmMnQzYiLHypk2DvWzUAuagWM8YihI/export?format=csv'
csv = CSV.parse(response.body)
sku_tag_mapping = {}
csv.each_with_index do |row, index|
next if index < 1
# Skip Variants without SKUs
next if row[0] == ''
next if row[0] == nil
# Skip Variants without Tags
next if row[2] == ''
next if row[2] == nil
sku_tag_mapping[row[0]] = row[2]
end
order = ShopifyAPI::Order.last
puts "\nProcessing Order:"
url_to_order = "https://resthouse.myshopify.com/admin/orders/#{order.id}"
url_to_customer = "https://resthouse.myshopify.com/admin/customers/#{order.customer.id}"
puts "<a href=\"#{url_to_order}\" target=\"_blank\">#{url_to_order}</a><br>"
customer = ShopifyAPI::Customer.find order.customer.id
order.line_items.each do |line|
puts line.title
if sku_tag_mapping.key?(line.sku)
customer.tags = "#{customer.tags}, #{sku_tag_mapping[line.sku]}"
end
end
puts "\nSaved Tags to:"
puts "<a href=\"#{url_to_customer}\" target=\"_blank\">#{url_to_customer}</a><br>"
customer.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment