can't get product id from shopify

9 views
Skip to first unread message

DrinDc

unread,
Oct 20, 2011, 3:39:45 AM10/20/11
to shopi...@googlegroups.com
hello all! This is my controller snippet,

def items
@products = ShopifyAPI::Product.find(:all)
  @products.each do |a| 
  @shop = Product.new(:title => a.title , :id => (a.id), :product_type => a.product_type)
  @shop.save
  end
  @shop_items =Product.find(:all)
redirect_to :action => "display_items"
end

but when i look at the id's, they are null. What am i doing wrong? thanks.

Eugene Bolshakov

unread,
Oct 20, 2011, 7:57:07 AM10/20/11
to shopi...@googlegroups.com
When you do this: 

Product.new(:title => a.title , :id => (a.id), :product_type => a.product_type)

the :id key is ignored. It's an ActiveRecord object and you're not supposed to set id (database primary key) for new objects.

If you want to store shopify product ids, I'd suggest adding a different field to your products table, e.g. shopify_product_id and set that instead:

Product.new(:title => a.title , :shopify_product_id =>  a.id, :product_type => a.product_type)
Reply all
Reply to author
Forward
0 new messages