2012-12-05 103 views
0

我想複製現有Shopify產品及其所有圖像和變體。如何使用Shopify複製產品gem

我該如何使用Shopify gem來做到這一點?

我正在運行Rails 3.2.2和Shopify gem 3.0.1。

感謝, 奧古斯托

更新#1:

我嘗試下面的代碼:

我認爲這個問題可能是我試圖創建一個新的產品與原始商品相同的shopifyid。但我不確定,我認爲可能還有其他問題。

original_p = ShopifyAPI::Product.find(xxx) 
new_p = ShopifyAPI::Product.new(original_p.attributes) 
new_p.save 

ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found. 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/connection.rb:136:in `handle_response' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/shopify_api-3.0.1/lib/active_resource/connection_ext.rb:9:in `handle_response_with_response_capture' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/connection.rb:115:in `request' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/shopify_api-3.0.1/lib/active_resource/connection_ext.rb:13:in `request_with_detailed_log_subscriber' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/connection.rb:92:in `block in put' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/connection.rb:218:in `with_auth' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/connection.rb:92:in `put' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/base.rb:1354:in `update' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/observing.rb:19:in `update_with_notifications' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/base.rb:1156:in `save' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/validations.rb:79:in `save_with_validation' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeresource-3.2.2/lib/active_resource/observing.rb:19:in `save_with_notifications' 
from (irb):26 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start' 
from /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>' 
from script/rails:6:in `require' 
from script/rails:6:in `<main>'1.9.2p290 :027 > np.errors 
+0

我建議您閱讀有關如何查找產品以及如何創建產品的Shopify文檔。 [顯示產品](http://api.shopify.com/product.html#show)和[創建產品](http://api.shopify.com/product.html#create) – Magicmarkker

+0

感謝Magicmarkker,但Shopify API文檔顯示瞭如何使用JSON創建新產品。我想使用Shopify gem(Ruby)複製現有產品。 – Augusto

+0

我不希望你爲我編寫代碼,但我需要一些幫助才能使用Shopify gem,而不是Shopify JSON API。 – Augusto

回答

1

以防萬一您還沒有找到解決方案。

  1. 我會建議先找到你希望複製並保存其信息到發言權本地數據庫中的產品(如重複Ojbect)
  2. 把你的本地版本,然後通過API創建

    product = ShopifyAPI::Product.create({ :body_html => duplicate.body_html, :title => duplicate.title })

duplicate是從當地:duplicate = Duplicate.find().last或類似的規定。