【问题标题】:Product creation using shopify gem returns 404 error使用 shopify gem 创建产品返回 404 错误
【发布时间】:2013-07-03 17:31:54
【问题描述】:

我正在尝试使用 shopify_api gem 将产品添加到商店。这是我试图用来执行此操作的代码:

ShopifyAPI::Base.authenticate
variant_shopify = ShopifyAPI::Variant.create(
                          :compare_at_price => @variant.compare_at_price,
                          :created_at => @variant.created_at,
                          :fulfillment_service => @variant.product.vendor.fulfillment_service.name,
                          :grams => @variant.grams,
                          :id => @variant.id,
                          :inventory_management => @variant.inventory_management,
                          :inventory_policy => @variant.inventory_policy,
                          :inventory_quantity => @variant.inventory_quantity,
                          :price => @variant.price,
                          :requires_shipping => @variant.requires_shipping,
                          :sku => @variant.sku,
                          :taxable => @variant.taxable,
                          :title => @variant.title,
                          :updated_at => @variant.updated_at)
product_shopify = ShopifyAPI::Product.create(
                          :body_html => @product.body_html,
                          :created_at => @product.created_at,
                          :id => @product.id,
                          :images => [{ :src => @product.image.url }],
                          :product_type => @product.product_type,
                          :published_at => @product.published_at,
                          :template_suffix => @product.template_suffix,
                          :title => @product.title,
                          :updated_at => @product.updated_at,
                          :variant => variant_shopify,
                          :vendor => @product.vendor.business_name)

但是,此代码会导致来自 shopify 的 404 响应。关于我能做什么的任何想法?感谢您的帮助

【问题讨论】:

    标签: ruby-on-rails ruby shopify


    【解决方案1】:

    您的代码毫无意义。让我们从您的产品创建声明开始。您正在尝试使用哈希创建产品。美好的。为什么您的哈希参数是产品实例变量?好的.. 撇开这些不谈,当您创建产品时,您会从 API 获得一个 ID。此外,它还提供 created_at 日期的时间戳。创建不是更新,因此您无需提供。

    假设您为@product 抓取了一个现有产品,那么您不仅需要提供与此相关的参数,而且还必须提供唯一的句柄。将其分解为首先解决该问题,然后一切都会随之而来。

    【讨论】:

    • 我正在创建一个全新的项目。产品实例变量是从字段填充的对象。有没有办法让shopify生成这个句柄,还是我应该自己生成并填写?
    • 花点时间看看 Shopify 是如何做到的。遵循他们的模式。它有效。
    • 我的意思是在第一句话中说产品而不是项目。也许这会导致某种误解,但是当您说“Shopify 是如何做到的”时,我真的不知道您的意思是什么,我也不知道从哪里获得这些信息。官方 API 页面主要介绍如何通过 POST 和 GET 请求与 shopify 交互,但并没有真正说明如何使用 gem,而似乎没有任何关于如何使用 gem 完全创建的资源新产品。如果您知道我应该查看哪些链接,那将非常有帮助。
    • 打开您的测试/开发商店并使用它添加产品。您将能够创建一个最小可行产品,然后您可以使用您的应用程序阅读该产品。检查退回的产品,然后您将能够反转该过程并创建一个全新的产品。对我来说,在没有至少一个开发商店供您使用的情况下尝试开发应用程序是没有意义的。它们是免费的,只需不到一分钟的时间即可完成设置。
    猜你喜欢
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多