简体   繁体   English

使用shopify gem创建产品会返回404错误

[英]Product creation using shopify gem returns 404 error

I'm trying to use the shopify_api gem to add products to a shop. 我正在尝试使用shopify_api gem将产品添加到商店。 Here is the code that I'm trying to use to do this: 这是我正在尝试使用的代码:

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)

However this code results in a 404 response from shopify. 但是,此代码会导致来自shopify的404响应。 Any ideas on what I could do? 关于我能做什么的任何想法? Thanks for the help in advnace 感谢您的帮助

Your code makes little sense. 您的代码毫无意义。 Let's take your product create statement to start with. 让我们以您的产品create语句开始。 You are trying to create a product using a hash. 您正在尝试使用哈希创建产品。 Fine. 精细。 Why are your hash parameters a product instance variable? 为什么您的哈希参数是产品实例变量? Ok.. leaving that aside, when you create a product, you get an ID, from API. 好吧..撇开它,当您创建产品时,您会从API获得ID。 Additionally, it provides a timestamp for the created_at date. 此外,它提供了created_at日期的时间戳。 A create is not an update so you do not provide that. 创建不是更新,因此您不提供更新。

Assuming you grabbed an existing product for @product, you would then be needing to feed not only the parameters from that that matter, but also you'd have to provide a unique handle. 假设您为@product抓住了一个现有产品,那么您不仅需要提供与此相关的参数,还需要提供唯一的句柄。 Strip it down to fixing that first, and all else will follow. 首先将其剥离,然后再进行其他修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM