使用Shopify_API Ruby gem创建带有图像的新产品 [英] Creating a new product with image using the shopify_api Ruby gem
本文介绍了使用Shopify_API Ruby gem创建带有图像的新产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Shopify有一个REST风格的API和一个我已经用来更新库存水平的方便的Shopify_API ruby gem。
今天我必须做一些新的事情,创建一个带镜像的新产品,我想使用Shopify_api gem,而不是使用睡觉客户端或httparty之类的东西来与接口交互。
Shopify API支持使用默认变体和产品镜像同时创建新产品,Shopify将使用此调用下载该产品:
post/admin/products ts.json
使用JSON请求字符串:
{
"product": {
"title": "Burton Custom Freestlye 151",
"body_html": "<strong>Good snowboard!</strong>",
"vendor": "Burton",
"product_type": "Snowboard",
"images": [
{
"src": "http://example.com/rails_logo.gif"
}
]
}
}
问题是如何使用Shopify_API gem执行此操作?
干杯,
马库斯
推荐答案
我发现了一种不雅致的做法。请参阅下面的解决方案:
images = []
image = {}
image["src"] = "http://i.dailymail.co.uk/i/pix/2012/09/10/article-0-14EE3D4E000005DC-303_634x434.jpg"
images << image
variant = ShopifyAPI::Variant.new(
:price => 69.99,
:inventory_management => 'shopify',
:inventory_quantity => 69,
:sku => "MS_TEST"
)
product = ShopifyAPI::Product.new(
:title => "MS Test",
:body_html => "<strong>Good snowboard!</strong>",
:vendor => "MS Test",
:product_type => "MS Test",
:images => images,
:variants => variant
)
这篇关于使用Shopify_API Ruby gem创建带有图像的新产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文