Last active
May 31, 2017 20:08
-
-
Save explorador/36362f6125f3a3dfbaa0e8a282a97f35 to your computer and use it in GitHub Desktop.
https://gist.github.com/explorador/36362f6125f3a3dfbaa0e8a282a97f35 https://help.shopify.com/api/tutorials/using-the-api-console https://github.com/shopify/shopify_cli Run: load "filename.rb"
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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