如何使用Shopify gem复制产品

时间:2012-12-05 17:20:03

标签: ruby-on-rails shopify

我想复制现有的Shopify产品及其所有图片和变体。

如何使用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

1 个答案:

答案 0 :(得分:1)

万一你找不到解决方案。

  1. 我建议先找一个你想要复制的产品并将其信息保存到一个本地数据库(例如Duplicate Ojbect)
  2. 获取您的本地版本,然后通过API

    创建

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

  3. duplicate来自您当地的duplicate = Duplicate.find().last或其他内容。