Skip to content

Instantly share code, notes, and snippets.

@explorador
Last active May 31, 2017 20:08
Show Gist options
  • Save explorador/36362f6125f3a3dfbaa0e8a282a97f35 to your computer and use it in GitHub Desktop.
Save explorador/36362f6125f3a3dfbaa0e8a282a97f35 to your computer and use it in GitHub Desktop.
include ShopifyAPI
# Reference: https://help.shopify.com/api/reference
objects = [ 'Blog', 'Article', 'Page', 'SmartCollection', 'Product', 'CustomCollection' ]
# Create directory if it doesn't exists
directory_name = "data"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# puts(variable); # Log
objects.each do |object|
File.write('./data/' + object + '.data', eval(object).all.to_json )
end
include ShopifyAPI
# Reference: https://help.shopify.com/api/reference
objects = [ 'Blog', 'Article', 'Page', 'SmartCollection', 'Product', 'CustomCollection' ]
# puts(variable); # Log
objects.each do |object|
objectJSON = JSON.parse(File.read('./data/' + object + '.data'))
objectJSON.each do |objectitem|
attr = objectitem;
# Remove some attributes which will through an error
attr.delete('id')
attr.delete('shopify_id')
# Create Object via API
i = eval(object).create(attr)
i.save()
end
end
include ShopifyAPI
d = JSON.parse(File.read('blogimages.data'))
d.each do |p|
attr = p;
id = attr['id'];
imageattr = attr['image'];
puts(id);
i = Article.find(id)
i.image = imageattr
i.save()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment