Skip to content

Instantly share code, notes, and snippets.

@CodeBrotha
Forked from Rolilink/shopify_example.rb
Created March 17, 2017 05:04
Show Gist options
  • Save CodeBrotha/e3e74e87014a83b28ae4e83a710e4a8d to your computer and use it in GitHub Desktop.
Save CodeBrotha/e3e74e87014a83b28ae4e83a710e4a8d to your computer and use it in GitHub Desktop.
# Saving a product from database
product = ShopifyAPI::Product.find(179761209) # This does an get http request to shopify api
db_product = DBProduct.new # You have to create a new rails model
db_product.shopify_id = product.id
db_product.save
# Saving a product to shopify
product.title = 'changed'
product.save # updates product in shopify, http put request
#Fetching the saved product in the database from shopify
product_from_db = DBProduct.all.first
shopify_product = ShopifyAPI::Product.find(product_from_db.shopidy_id) # This does an get http request to shopify api with the id you saved in the database
# Creating a product in shopify
product = ShopifyAPI::Product.create({attrs..}) # just give it a hash with the required attributes
#Another way
product = ShopifyAPI::Product.new
product.title = 'shoes'
product.description = 'this is a shoe'
product.save # here it does an http request not a database one, if you want to save into database create a new model to save this information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment