0
我正嘗試使用shopify_api gem向商店添加產品。以下是我正在嘗試使用的代碼:使用shopify gem產品創建返回404錯誤
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響應。關於我能做什麼的任何想法?感謝您在advnace的幫助
我正在創建一個全新的項目。產品實例變量是從字段填充的對象。有沒有辦法讓shopify生成這個句柄,或者我應該生成它並自己填充它? – fizzy123
花點時間看看Shopify是如何做到的。按照他們的模式。有用。 –
我打算在第一句話中說產品而不是項目。也許這會導致某種誤解,但當你說「Shopify如何做」時,我並不確定你的意思,我也不知道從哪裏得到這些信息。官方的API頁面主要涉及如何通過POST和GET請求與shopify進行交互,但並沒有真正講述如何使用gem,而似乎沒有任何關於如何使用gem來創建的資源新產品。如果你知道我應該看的鏈接,這些鏈接將非常有幫助。 – fizzy123